Commit 3c62bb74 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API] polymorphic node for rest api.

parent d89f060c
......@@ -27,7 +27,7 @@ import Control.Monad.IO.Class (liftIO)
import Control.Monad ((>>))
--import System.IO (putStrLn, readFile)
-- import Data.Aeson (Value())
import Data.Aeson (Value())
--import Data.Text (Text(), pack)
import Data.Text (Text())
import Data.Time (UTCTime)
......@@ -48,20 +48,20 @@ import Gargantext.Database.Facet (FacetDoc, getDocFacet
-------------------------------------------------------------------
-------------------------------------------------------------------
-- | Node API Types management
type Roots = Get '[JSON] [Node HyperdataDocument]
type Roots = Get '[JSON] [Node Value]
:<|> Post '[JSON] Int
:<|> Put '[JSON] Int
:<|> Delete '[JSON] Int
type NodesAPI = Delete '[JSON] Int
type NodeAPI = Get '[JSON] (Node HyperdataDocument)
type NodeAPI = Get '[JSON] (Node Value)
:<|> Delete '[JSON] Int
:<|> "children" :> Summary " Summary children"
:> QueryParam "type" NodeType
:> QueryParam "offset" Int
:> QueryParam "limit" Int
:> Get '[JSON] [Node HyperdataDocument]
:> Get '[JSON] [Node Value]
:<|> "facet" :> Summary " Facet documents"
:> "documents" :> FacetDocAPI
-- :<|> "facet" :<|> "sources" :<|> FacetSourcesAPI
......@@ -120,7 +120,7 @@ deleteNode' :: Connection -> NodeId -> Handler Int
deleteNode' conn id = liftIO (deleteNode conn id)
getNodesWith' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe Int
-> Handler [Node HyperdataDocument]
-> Handler [Node Value]
getNodesWith' conn id nodeType offset limit = liftIO (getNodesWith conn id nodeType offset limit)
......
......@@ -301,6 +301,12 @@ instance ToSchema HyperdataDocument where
L.& mapped.schema.example ?~ toJSON hyperdataDocument
instance ToSchema Value where
declareNamedSchema proxy = genericDeclareNamedSchemaUnrestricted defaultSchemaOptions proxy
L.& mapped.schema.description ?~ "a document"
L.& mapped.schema.example ?~ toJSON ("" :: Text)
instance ToSchema (NodePoly NodeId NodeTypeId NodeUserId
(Maybe NodeParentId) NodeName
UTCTime HyperdataDocument
......@@ -312,6 +318,19 @@ instance ToSchema (NodePoly NodeId NodeTypeId
UTCTime HyperdataDocument
)
instance ToSchema (NodePoly NodeId NodeTypeId
(Maybe NodeUserId)
NodeParentId NodeName
UTCTime Value
)
instance ToSchema (NodePoly NodeId NodeTypeId
(NodeUserId)
(Maybe NodeParentId) NodeName
UTCTime Value
)
instance ToSchema Status
......@@ -161,9 +161,9 @@ post' = do
c <- connectGargandb "gargantext.ini"
pid <- last <$> home c
let uid = 1
postNode c uid pid ( Node' Corpus (pack "Premier corpus") (toJSON ("{}"::Text)) [ Node' Document (pack "Doc1") (toJSON ("{}" :: Text)) []
postNode c uid pid ( Node' Corpus (pack "Premier corpus") (toJSON (pack "{}"::Text)) [ Node' Document (pack "Doc1") (toJSON (pack "{}" :: Text)) []
, Node' Document (pack "Doc2") (toJSON (pack "{}" :: Text)) []
, Node' Document (pack "Doc3") (toJSON ("{}" :: Text)) []
, Node' Document (pack "Doc3") (toJSON (pack "{}" :: Text)) []
]
)
......@@ -174,7 +174,7 @@ postCorpus corpusName title ns = do
c <- connectGargandb "gargantext.ini"
pid <- last <$> home c
let uid = 1
postNode c uid pid ( Node' Corpus corpusName (toJSON ("{}"::Text))
postNode c uid pid ( Node' Corpus corpusName (toJSON (pack "{}"::Text))
(map (\n -> Node' Document (title n) (toJSON n) []) ns)
)
......@@ -186,7 +186,7 @@ postAnnuaire corpusName title ns = do
c <- connectGargandb "gargantext.ini"
pid <- last <$> home c
let uid = 1
postNode c uid pid ( Node' Annuaire corpusName (toJSON ("{}"::Text))
postNode c uid pid ( Node' Annuaire corpusName (toJSON (pack "{}"::Text))
(map (\n -> Node' UserPage (title n) (toJSON n) []) ns)
)
......
......@@ -189,7 +189,7 @@ deleteNodes conn ns = fromIntegral <$> runDelete conn nodeTable
getNodesWith :: Connection -> Int -> Maybe NodeType
-> Maybe Offset -> Maybe Limit -> IO [Node HyperdataDocument]
-> Maybe Offset -> Maybe Limit -> IO [Node Value]
getNodesWith conn parentId nodeType maybeOffset maybeLimit =
runQuery conn $ selectNodesWith
parentId nodeType maybeOffset maybeLimit
......@@ -197,7 +197,7 @@ getNodesWith conn parentId nodeType maybeOffset maybeLimit =
-- NP check type
getNodesWithParentId :: Connection -> Int
-> Maybe Text -> IO [Node HyperdataDocument]
-> Maybe Text -> IO [Node Value]
getNodesWithParentId conn n _ = runQuery conn $ selectNodesWithParentID n
getNodesWithParentId' :: Connection -> Int
......@@ -227,7 +227,7 @@ getNode' c id = do
fromMaybe (error "TODO: 404") . headMay <$> runQuery c (limit 1 $ selectNode (pgInt4 id))
getNode :: Connection -> Int -> IO (Node HyperdataDocument)
getNode :: Connection -> Int -> IO (Node Value)
getNode conn id = do
fromMaybe (error "TODO: 404") . headMay <$> runQuery conn (limit 1 $ selectNode (pgInt4 id))
......
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