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
147
Issues
147
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
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
3c62bb74
Commit
3c62bb74
authored
Jun 18, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API] polymorphic node for rest api.
parent
d89f060c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
12 deletions
+31
-12
Node.hs
src/Gargantext/API/Node.hs
+5
-5
Node.hs
src/Gargantext/Core/Types/Node.hs
+19
-0
Database.hs
src/Gargantext/Database.hs
+4
-4
Node.hs
src/Gargantext/Database/Node.hs
+3
-3
No files found.
src/Gargantext/API/Node.hs
View file @
3c62bb74
...
...
@@ -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
'[
J
SON
]
[
Node
HyperdataDocument
]
type
Roots
=
Get
'[
J
SON
]
[
Node
Value
]
:<|>
Post
'[
J
SON
]
Int
:<|>
Put
'[
J
SON
]
Int
:<|>
Delete
'[
J
SON
]
Int
type
NodesAPI
=
Delete
'[
J
SON
]
Int
type
NodeAPI
=
Get
'[
J
SON
]
(
Node
HyperdataDocument
)
type
NodeAPI
=
Get
'[
J
SON
]
(
Node
Value
)
:<|>
Delete
'[
J
SON
]
Int
:<|>
"children"
:>
Summary
" Summary children"
:>
QueryParam
"type"
NodeType
:>
QueryParam
"offset"
Int
:>
QueryParam
"limit"
Int
:>
Get
'[
J
SON
]
[
Node
HyperdataDocument
]
:>
Get
'[
J
SON
]
[
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
)
...
...
src/Gargantext/Core/Types/Node.hs
View file @
3c62bb74
...
...
@@ -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
src/Gargantext/Database.hs
View file @
3c62bb74
...
...
@@ -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
)
)
...
...
src/Gargantext/Database/Node.hs
View file @
3c62bb74
...
...
@@ -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
))
...
...
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