Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
158
Issues
158
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
6f26b61f
Commit
6f26b61f
authored
Feb 14, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API/Database] Delete Node and Nodes added.
parent
0b32959b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
7 deletions
+32
-7
API.hs
src/Gargantext/API.hs
+8
-2
Node.hs
src/Gargantext/API/Node.hs
+16
-1
Node.hs
src/Gargantext/Database/Node.hs
+8
-4
No files found.
src/Gargantext/API.hs
View file @
6f26b61f
...
@@ -30,7 +30,10 @@ import System.IO (FilePath, print)
...
@@ -30,7 +30,10 @@ import System.IO (FilePath, print)
-- import Gargantext.API.Auth
-- 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
)
import
Gargantext.Database.Private
(
databaseParameters
)
...
@@ -47,7 +50,9 @@ startGargantext port file = do
...
@@ -47,7 +50,9 @@ startGargantext port file = do
-- | Main routes of the API are typed
-- | Main routes of the API are typed
type
API
=
"roots"
:>
Roots
type
API
=
"roots"
:>
Roots
:<|>
"node"
:>
Capture
"id"
Int
:>
NodeAPI
:<|>
"node"
:>
Capture
"id"
Int
:>
NodeAPI
:<|>
"nodes"
:>
ReqBody
'[
J
SON
]
[
Int
]
:>
NodesAPI
-- :<|> "static"
-- :<|> "static"
-- :<|> "list" :> Capture "id" Int :> NodeAPI
-- :<|> "list" :> Capture "id" Int :> NodeAPI
-- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
-- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
...
@@ -58,6 +63,7 @@ type API = "roots" :> Roots
...
@@ -58,6 +63,7 @@ type API = "roots" :> Roots
server
::
Connection
->
Server
API
server
::
Connection
->
Server
API
server
conn
=
roots
conn
server
conn
=
roots
conn
:<|>
nodeAPI
conn
:<|>
nodeAPI
conn
:<|>
nodesAPI
conn
-- | TODO App type, the main monad in which the bot code is written with.
-- | TODO App type, the main monad in which the bot code is written with.
-- Provide config, state, logs and IO
-- Provide config, state, logs and IO
...
...
src/Gargantext/API/Node.hs
View file @
6f26b61f
...
@@ -28,13 +28,18 @@ import Data.Text (Text(), pack)
...
@@ -28,13 +28,18 @@ import Data.Text (Text(), pack)
import
Database.PostgreSQL.Simple
(
Connection
)
import
Database.PostgreSQL.Simple
(
Connection
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Types.Main
(
Node
,
NodeId
,
NodeType
)
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
-- | Node API Types management
type
Roots
=
Get
'[
J
SON
]
[
Node
Value
]
type
Roots
=
Get
'[
J
SON
]
[
Node
Value
]
type
NodesAPI
=
Delete
'[
J
SON
]
Int
type
NodeAPI
=
Get
'[
J
SON
]
(
Node
Value
)
type
NodeAPI
=
Get
'[
J
SON
]
(
Node
Value
)
:<|>
Delete
'[
J
SON
]
Int
-- Example for Document Facet view, to populate the tabular:
-- Example for Document Facet view, to populate the tabular:
-- http://localhost:8008/node/347476/children?type=Document&limit=3
-- http://localhost:8008/node/347476/children?type=Document&limit=3
...
@@ -61,10 +66,20 @@ roots conn = liftIO (getNodesWithParentId conn 0 Nothing)
...
@@ -61,10 +66,20 @@ roots conn = liftIO (getNodesWithParentId conn 0 Nothing)
nodeAPI
::
Connection
->
NodeId
->
Server
NodeAPI
nodeAPI
::
Connection
->
NodeId
->
Server
NodeAPI
nodeAPI
conn
id
=
liftIO
(
getNode
conn
id
)
nodeAPI
conn
id
=
liftIO
(
getNode
conn
id
)
:<|>
deleteNode'
conn
id
:<|>
getNodesWith'
conn
id
:<|>
getNodesWith'
conn
id
:<|>
upload
:<|>
upload
:<|>
query
:<|>
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
getNodesWith'
::
Connection
->
NodeId
->
Maybe
NodeType
->
Maybe
Int
->
Maybe
Int
->
Handler
[
Node
Value
]
->
Handler
[
Node
Value
]
getNodesWith'
conn
id
nodeType
offset
limit
=
liftIO
(
getNodesWith
conn
id
nodeType
offset
limit
)
getNodesWith'
conn
id
nodeType
offset
limit
=
liftIO
(
getNodesWith
conn
id
nodeType
offset
limit
)
...
...
src/Gargantext/Database/Node.hs
View file @
6f26b61f
...
@@ -25,7 +25,7 @@ import Database.PostgreSQL.Simple.FromField ( Conversion
...
@@ -25,7 +25,7 @@ import Database.PostgreSQL.Simple.FromField ( Conversion
,
fromField
,
fromField
,
returnError
,
returnError
)
)
import
Prelude
hiding
(
null
,
id
)
import
Prelude
hiding
(
null
,
id
,
map
)
import
Gargantext.Types.Main
(
NodeType
)
import
Gargantext.Types.Main
(
NodeType
)
import
Database.PostgreSQL.Simple.Internal
(
Field
)
import
Database.PostgreSQL.Simple.Internal
(
Field
)
import
Control.Arrow
(
returnA
)
import
Control.Arrow
(
returnA
)
...
@@ -151,7 +151,6 @@ offset' :: Maybe Offset -> Query NodeRead -> Query NodeRead
...
@@ -151,7 +151,6 @@ offset' :: Maybe Offset -> Query NodeRead -> Query NodeRead
offset'
maybeOffset
query
=
maybe
query
(
\
o
->
offset
o
query
)
maybeOffset
offset'
maybeOffset
query
=
maybe
query
(
\
o
->
offset
o
query
)
maybeOffset
-- Add order by
selectNodesWith'
::
ParentId
->
Maybe
NodeType
->
Query
NodeRead
selectNodesWith'
::
ParentId
->
Maybe
NodeType
->
Query
NodeRead
selectNodesWith'
parentId
maybeNodeType
=
proc
()
->
do
selectNodesWith'
parentId
maybeNodeType
=
proc
()
->
do
node
<-
(
proc
()
->
do
node
<-
(
proc
()
->
do
...
@@ -167,8 +166,13 @@ selectNodesWith' parentId maybeNodeType = proc () -> do
...
@@ -167,8 +166,13 @@ selectNodesWith' parentId maybeNodeType = proc () -> do
returnA
-<
node
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
]
getNodesWith
::
Connection
->
Int
->
Maybe
NodeType
->
Maybe
Offset
->
Maybe
Limit
->
IO
[
Node
Value
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment