diff --git a/src/Gargantext/API/Node.hs b/src/Gargantext/API/Node.hs index e108cec1a0b8c89309c304bee743d3a330875e04..a74b3e6d9b58c54827f8d9dae35a0dd75bb91d1c 100644 --- a/src/Gargantext/API/Node.hs +++ b/src/Gargantext/API/Node.hs @@ -27,10 +27,11 @@ import System.IO (putStrLn, readFile) import Data.Text (Text(), pack) import Database.PostgreSQL.Simple (Connection) import Gargantext.Prelude -import Gargantext.Types.Main (Node, NodeId, NodeType) +import Gargantext.Types.Main (Node, NodeId, NodeType, FacetDoc) import Gargantext.Database.Node (getNodesWithParentId , getNode, getNodesWith - , deleteNode, deleteNodes) + , deleteNode, deleteNodes + , getDocFacet) -- | Node API Types management @@ -41,15 +42,18 @@ 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 - -- /!\ FIXME : nodeType is case sensitive - -- /!\ see NodeTypes in Types/Main.hs :<|> "children" :> QueryParam "type" NodeType :> QueryParam "offset" Int :> QueryParam "limit" Int :> Get '[JSON] [Node Value] - + + + :<|> "facetDoc" :> QueryParam "type" NodeType + :> QueryParam "offset" Int + :> QueryParam "limit" Int + :> Get '[JSON] [FacetDoc Value] + + -- Depending on the Type of the Node, we could post -- New documents for a corpus -- New map list terms @@ -66,8 +70,9 @@ roots conn = liftIO (getNodesWithParentId conn 0 Nothing) nodeAPI :: Connection -> NodeId -> Server NodeAPI nodeAPI conn id = liftIO (getNode conn id) - :<|> deleteNode' conn id + :<|> deleteNode' conn id :<|> getNodesWith' conn id + :<|> getDocFacet' conn id :<|> upload :<|> query @@ -84,6 +89,9 @@ getNodesWith' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe In -> Handler [Node Value] getNodesWith' conn id nodeType offset limit = liftIO (getNodesWith conn id nodeType offset limit) +getDocFacet' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe Int + -> Handler [FacetDoc Value] +getDocFacet' conn id nodeType offset limit = liftIO (getDocFacet conn id nodeType offset limit) query :: Text -> Handler Text query s = pure s diff --git a/src/Gargantext/Database/Private.hs b/src/Gargantext/Database/Private.hs index 34618eae06d014cb82c8c2d0c0ee942308c4e368..2fb49dc366de837d6afd6d39b27116102ae8bc68 100644 --- a/src/Gargantext/Database/Private.hs +++ b/src/Gargantext/Database/Private.hs @@ -13,6 +13,7 @@ import Text.Read (read) import Data.Ini (readIniFile, lookupValue) import Data.Word (Word16) import System.IO (FilePath) +import Database.PostgreSQL.Simple (Connection, connect) -- TODO add a reader Monad here -- read this in the init file @@ -34,5 +35,7 @@ databaseParameters fp = do , PGS.connectPassword = val "DB_PASS" , PGS.connectDatabase = val "DB_NAME" } - - +connectGargandb :: FilePath -> IO Connection +connectGargandb fp = do + parameters <- databaseParameters fp + connect parameters