Small refactoring of the calls which creates a node

parent 930b75fc
...@@ -285,15 +285,17 @@ serverGargAPI :: GargServer GargAPI ...@@ -285,15 +285,17 @@ serverGargAPI :: GargServer GargAPI
serverGargAPI -- orchestrator serverGargAPI -- orchestrator
= auth = auth
:<|> roots :<|> roots
:<|> nodeAPI (Proxy :: Proxy HyperdataAny) :<|> nodeAPI (Proxy :: Proxy HyperdataAny) fakeUserId
:<|> nodeAPI (Proxy :: Proxy HyperdataCorpus) :<|> nodeAPI (Proxy :: Proxy HyperdataCorpus) fakeUserId
:<|> nodeAPI (Proxy :: Proxy HyperdataAnnuaire) :<|> nodeAPI (Proxy :: Proxy HyperdataAnnuaire) fakeUserId
:<|> nodesAPI :<|> nodesAPI
:<|> count -- TODO: undefined :<|> count -- TODO: undefined
:<|> search :<|> search
:<|> graphAPI -- TODO: mock :<|> graphAPI -- TODO: mock
:<|> treeAPI :<|> treeAPI
-- :<|> orchestrator -- :<|> orchestrator
where
fakeUserId = 1 -- TODO
serverIndex :: Server (Get '[HTML] Html) serverIndex :: Server (Get '[HTML] Html)
serverIndex = $(do (Just s) <- liftIO (fileTypeToFileTree (FileTypeFile "purescript-gargantext/dist/index.html")) serverIndex = $(do (Just s) <- liftIO (fileTypeToFileTree (FileTypeFile "purescript-gargantext/dist/index.html"))
......
...@@ -50,7 +50,7 @@ import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, TableNgramsApiGet, ta ...@@ -50,7 +50,7 @@ import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, TableNgramsApiGet, ta
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Database.Types.Node import Gargantext.Database.Types.Node
import Gargantext.Database.Utils -- (Cmd, CmdM) import Gargantext.Database.Utils -- (Cmd, CmdM)
import Gargantext.Database.Schema.Node ( getNodesWithParentId, getNode, deleteNode, deleteNodes, mk, JSONB, NodeError(..), HasNodeError(..)) import Gargantext.Database.Schema.Node ( getNodesWithParentId, getNode, deleteNode, deleteNodes, mkNodeWithParent, JSONB, NodeError(..), HasNodeError(..))
import Gargantext.Database.Node.Children (getChildren) import Gargantext.Database.Node.Children (getChildren)
import qualified Gargantext.Database.Node.Update as U (update, Update(..)) import qualified Gargantext.Database.Node.Update as U (update, Update(..))
import Gargantext.Database.Facet (FacetDoc , runViewDocuments, OrderBy(..),FacetChart,runViewAuthorsDoc) import Gargantext.Database.Facet (FacetDoc , runViewDocuments, OrderBy(..),FacetChart,runViewAuthorsDoc)
...@@ -136,10 +136,11 @@ type ChildrenApi a = Summary " Summary children" ...@@ -136,10 +136,11 @@ type ChildrenApi a = Summary " Summary children"
:> Get '[JSON] [Node a] :> Get '[JSON] [Node a]
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- TODO: make the NodeId type indexed by `a`, then we no longer need the proxy. -- TODO: make the NodeId type indexed by `a`, then we no longer need the proxy.
nodeAPI :: JSONB a => proxy a -> NodeId -> GargServer (NodeAPI a) nodeAPI :: JSONB a => proxy a -> UserId -> NodeId -> GargServer (NodeAPI a)
nodeAPI p id = getNode id p nodeAPI p uId id
= getNode id p
:<|> rename id :<|> rename id
:<|> postNode id :<|> postNode uId id
:<|> putNode id :<|> putNode id
:<|> deleteNode id :<|> deleteNode id
:<|> getChildren id p :<|> getChildren id p
...@@ -330,8 +331,8 @@ getChart :: NodeId -> Maybe UTCTime -> Maybe UTCTime ...@@ -330,8 +331,8 @@ getChart :: NodeId -> Maybe UTCTime -> Maybe UTCTime
-> Cmd err [FacetChart] -> Cmd err [FacetChart]
getChart _ _ _ = undefined -- TODO getChart _ _ _ = undefined -- TODO
postNode :: NodeId -> PostNode -> Cmd err [NodeId] postNode :: HasNodeError err => UserId -> NodeId -> PostNode -> Cmd err [NodeId]
postNode pId (PostNode name nt) = mk nt (Just pId) name postNode uId pId (PostNode name nt) = mkNodeWithParent nt (Just pId) uId name
putNode :: NodeId -> Cmd err Int putNode :: NodeId -> Cmd err Int
putNode = undefined -- TODO putNode = undefined -- TODO
......
...@@ -500,29 +500,20 @@ childWith uId pId (Node' NodeContact txt v []) = node2table uId (Just pId) (Nod ...@@ -500,29 +500,20 @@ childWith uId pId (Node' NodeContact txt v []) = node2table uId (Just pId) (Nod
childWith _ _ (Node' _ _ _ _) = panic "This NodeType can not be a child" childWith _ _ (Node' _ _ _ _) = panic "This NodeType can not be a child"
-- | TODO Use right userId type Name = Text
mk :: NodeType -> Maybe ParentId -> Text -> Cmd err [NodeId]
mk nt pId name = mk' nt userId pId name
where
userId = 1
mk' :: NodeType -> UserId -> Maybe ParentId -> Text -> Cmd err [NodeId] mkNodeWithParent :: HasNodeError err => NodeType -> Maybe ParentId -> UserId -> Name -> Cmd err [NodeId]
mk' nt uId pId name = insertNodesWithParentR pId [node nt name hd pId uId] mkNodeWithParent NodeUser (Just _) _ _ = nodeError UserNoParent
mkNodeWithParent _ Nothing _ _ = nodeError HasParent
mkNodeWithParent nt pId uId name =
insertNodesWithParentR pId [node nt name hd pId uId]
where where
hd = HyperdataUser . Just . pack $ show EN hd = HyperdataUser . Just . pack $ show EN
type Name = Text
mk'' :: HasNodeError err => NodeType -> Maybe ParentId -> UserId -> Name -> Cmd err [NodeId]
mk'' NodeUser Nothing uId name = mk' NodeUser uId Nothing name
mk'' NodeUser _ _ _ = nodeError UserNoParent
mk'' _ Nothing _ _ = nodeError HasParent
mk'' nt pId uId name = mk' nt uId pId name
mkRoot :: HasNodeError err => Username -> UserId -> Cmd err [RootId] mkRoot :: HasNodeError err => Username -> UserId -> Cmd err [RootId]
mkRoot uname uId = case uId > 0 of mkRoot uname uId = case uId > 0 of
False -> nodeError NegativeId False -> nodeError NegativeId
True -> mk'' NodeUser Nothing uId uname True -> mkNodeWithParent NodeUser Nothing uId uname
mkCorpus :: Maybe Name -> Maybe HyperdataCorpus -> ParentId -> UserId -> Cmd err [CorpusId] mkCorpus :: Maybe Name -> Maybe HyperdataCorpus -> ParentId -> UserId -> Cmd err [CorpusId]
mkCorpus n h p u = insertNodesR [nodeCorpusW n h p u] mkCorpus n h p u = insertNodesR [nodeCorpusW n h p u]
......
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