Commit 6f26b61f authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API/Database] Delete Node and Nodes added.

parent 0b32959b
......@@ -30,7 +30,10 @@ import System.IO (FilePath, print)
-- import Gargantext.API.Auth
import Gargantext.API.Node (Roots, roots, NodeAPI, nodeAPI)
import Gargantext.API.Node ( Roots , roots
, NodeAPI , nodeAPI
, NodesAPI , nodesAPI
)
import Gargantext.Database.Private (databaseParameters)
......@@ -48,6 +51,8 @@ startGargantext port file = do
-- | Main routes of the API are typed
type API = "roots" :> Roots
:<|> "node" :> Capture "id" Int :> NodeAPI
:<|> "nodes" :> ReqBody '[JSON] [Int] :> NodesAPI
-- :<|> "static"
-- :<|> "list" :> Capture "id" Int :> NodeAPI
-- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
......@@ -58,6 +63,7 @@ type API = "roots" :> Roots
server :: Connection -> Server API
server conn = roots conn
:<|> nodeAPI conn
:<|> nodesAPI conn
-- | TODO App type, the main monad in which the bot code is written with.
-- Provide config, state, logs and IO
......
......@@ -28,13 +28,18 @@ import Data.Text (Text(), pack)
import Database.PostgreSQL.Simple (Connection)
import Gargantext.Prelude
import Gargantext.Types.Main (Node, NodeId, NodeType)
import Gargantext.Database.Node (getNodesWithParentId, getNode, getNodesWith)
import Gargantext.Database.Node (getNodesWithParentId
, getNode, getNodesWith
, deleteNode, deleteNodes)
-- | Node API Types management
type Roots = Get '[JSON] [Node Value]
type NodesAPI = Delete '[JSON] Int
type NodeAPI = Get '[JSON] (Node Value)
:<|> Delete '[JSON] Int
-- Example for Document Facet view, to populate the tabular:
-- http://localhost:8008/node/347476/children?type=Document&limit=3
......@@ -61,10 +66,20 @@ roots conn = liftIO (getNodesWithParentId conn 0 Nothing)
nodeAPI :: Connection -> NodeId -> Server NodeAPI
nodeAPI conn id = liftIO (getNode conn id)
:<|> deleteNode' conn id
:<|> getNodesWith' conn id
:<|> upload
:<|> query
nodesAPI :: Connection -> [NodeId] -> Server NodesAPI
nodesAPI conn ids = deleteNodes' conn ids
deleteNodes' :: Connection -> [NodeId] -> Handler Int
deleteNodes' conn ids = liftIO (deleteNodes conn ids)
deleteNode' :: Connection -> NodeId -> Handler Int
deleteNode' conn id = liftIO (deleteNode conn id)
getNodesWith' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe Int
-> Handler [Node Value]
getNodesWith' conn id nodeType offset limit = liftIO (getNodesWith conn id nodeType offset limit)
......
......@@ -25,7 +25,7 @@ import Database.PostgreSQL.Simple.FromField ( Conversion
, fromField
, returnError
)
import Prelude hiding (null, id)
import Prelude hiding (null, id, map)
import Gargantext.Types.Main (NodeType)
import Database.PostgreSQL.Simple.Internal (Field)
import Control.Arrow (returnA)
......@@ -151,7 +151,6 @@ offset' :: Maybe Offset -> Query NodeRead -> Query NodeRead
offset' maybeOffset query = maybe query (\o -> offset o query) maybeOffset
-- Add order by
selectNodesWith' :: ParentId -> Maybe NodeType -> Query NodeRead
selectNodesWith' parentId maybeNodeType = proc () -> do
node <- (proc () -> do
......@@ -167,8 +166,13 @@ selectNodesWith' parentId maybeNodeType = proc () -> do
returnA -< node
--getNodesWith' :: Connection -> Int -> Maybe NodeType -> Maybe Offset' -> Maybe Limit' -> IO [Node Value]
--getNodesWith' conn parentId maybeNodeType maybeOffset maybeLimit = runQuery conn $ selectNodesWith parentId xxx maybeOffset maybeLimit
deleteNode :: Connection -> Int -> IO Int
deleteNode conn n = fromIntegral <$> runDelete conn nodeTable (\(Node n_id _ _ _ _ _ _) -> n_id .== pgInt4 n)
deleteNodes :: Connection -> [Int] -> IO Int
deleteNodes conn ns = fromIntegral <$> runDelete conn nodeTable (\(Node n_id _ _ _ _ _ _) -> in_ ((map pgInt4 ns)) n_id)
getNodesWith :: Connection -> Int -> Maybe NodeType -> Maybe Offset -> Maybe Limit -> IO [Node Value]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment