Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
haskell-gargantext
Commits
1ee35a9a
Commit
1ee35a9a
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
7197391f
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 @
1ee35a9a
...
...
@@ -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
)
...
...
@@ -47,7 +50,9 @@ startGargantext port file = do
-- | Main routes of the API are typed
type
API
=
"roots"
:>
Roots
:<|>
"node"
:>
Capture
"id"
Int
:>
NodeAPI
:<|>
"node"
:>
Capture
"id"
Int
:>
NodeAPI
:<|>
"nodes"
:>
ReqBody
'[
J
SON
]
[
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
...
...
src/Gargantext/API/Node.hs
View file @
1ee35a9a
...
...
@@ -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
'[
J
SON
]
[
Node
Value
]
type
NodesAPI
=
Delete
'[
J
SON
]
Int
type
NodeAPI
=
Get
'[
J
SON
]
(
Node
Value
)
:<|>
Delete
'[
J
SON
]
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
)
...
...
src/Gargantext/Database/Node.hs
View file @
1ee35a9a
...
...
@@ -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
]
...
...
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