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
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
Christian Merten
haskell-gargantext
Commits
38449989
Commit
38449989
authored
Oct 22, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API] Favorites + documents (toTrash) routes.
parent
ebe23369
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
34 deletions
+84
-34
API.hs
src/Gargantext/API.hs
+0
-3
Node.hs
src/Gargantext/API/Node.hs
+76
-25
NodeNode.hs
src/Gargantext/Database/NodeNode.hs
+8
-6
No files found.
src/Gargantext/API.hs
View file @
38449989
...
...
@@ -206,16 +206,13 @@ type GargAPI' =
"user"
:>
Summary
"First user endpoint"
:>
Roots
-- Node endpoint
:<|>
"node"
:>
Summary
"Node endpoint"
:>
Capture
"id"
Int
:>
NodeAPI
Value
-- Corpus endpoint
:<|>
"corpus"
:>
Summary
"Corpus endpoint"
:>
Capture
"id"
Int
:>
NodeAPI
HyperdataCorpus
-- Corpus endpoint
:<|>
"nodes"
:>
Summary
"Nodes endpoint"
:>
ReqBody
'[
J
SON
]
[
Int
]
:>
NodesAPI
...
...
src/Gargantext/API/Node.hs
View file @
38449989
...
...
@@ -52,13 +52,13 @@ import Gargantext.Prelude
import
Gargantext.Database.Types.Node
import
Gargantext.Database.Node
(
runCmd
,
getNodesWithParentId
,
getNode
,
getNodesWith
,
getNode
,
getNodesWith
,
CorpusId
,
deleteNode
,
deleteNodes
,
mk
,
JSONB
)
import
qualified
Gargantext.Database.Node.Update
as
U
(
update
,
Update
(
..
))
import
Gargantext.Database.Facet
(
FacetDoc
,
runViewDocuments'
,
OrderBy
(
..
)
,
FacetChart
)
import
Gargantext.Database.Tree
(
treeDB
,
HasTreeError
(
..
),
TreeError
(
..
))
import
Gargantext.Database.NodeNode
(
nodesToFavorite
,
nodesToTrash
)
-- Graph
import
Gargantext.TextFlow
import
Gargantext.Viz.Graph
(
Graph
)
...
...
@@ -103,6 +103,48 @@ instance Arbitrary PostNode where
arbitrary
=
elements
[
PostNode
"Node test"
NodeCorpus
]
------------------------------------------------------------------------
type
DocsApi
=
"documents"
:>
Summary
"Docs api"
:>
ReqBody
'[
J
SON
]
Documents
:>
Delete
'[
J
SON
]
[
Int
]
data
Documents
=
Documents
{
documents
::
[
NodeId
]}
deriving
(
Generic
)
instance
FromJSON
Documents
instance
ToJSON
Documents
instance
ToSchema
Documents
delDocs
::
Connection
->
CorpusId
->
Documents
->
Handler
[
Int
]
delDocs
c
cId
ds
=
liftIO
$
nodesToTrash
c
$
map
(
\
n
->
(
cId
,
n
,
True
))
$
documents
ds
------------------------------------------------------------------------
type
FavApi
=
"favorites"
:>
Summary
"Modify statut"
:>
ReqBody
'[
J
SON
]
Favorites
:>
Put
'[
J
SON
]
[
Int
]
:<|>
Summary
"Delete"
:>
ReqBody
'[
J
SON
]
Favorites
:>
Delete
'[
J
SON
]
[
Int
]
data
Favorites
=
Favorites
{
favorites
::
[
NodeId
]}
deriving
(
Generic
)
instance
FromJSON
Favorites
instance
ToJSON
Favorites
instance
ToSchema
Favorites
putFav
::
Connection
->
CorpusId
->
Favorites
->
Handler
[
Int
]
putFav
c
cId
fs
=
liftIO
$
nodesToFavorite
c
$
map
(
\
n
->
(
cId
,
n
,
True
))
$
favorites
fs
delFav
::
Connection
->
CorpusId
->
Favorites
->
Handler
[
Int
]
delFav
c
cId
fs
=
liftIO
$
nodesToFavorite
c
$
map
(
\
n
->
(
cId
,
n
,
False
))
$
favorites
fs
favApi
::
Connection
->
CorpusId
->
(
Favorites
->
Handler
[
Int
])
:<|>
(
Favorites
->
Handler
[
Int
])
favApi
c
cId
=
putFav
c
cId
:<|>
delFav
c
cId
------------------------------------------------------------------------
type
NodeAPI
a
=
Get
'[
J
SON
]
(
Node
a
)
:<|>
"rename"
:>
Summary
" RenameNode Node"
...
...
@@ -118,7 +160,25 @@ type NodeAPI a = Get '[JSON] (Node a)
:>
QueryParam
"offset"
Int
:>
QueryParam
"limit"
Int
:>
Get
'[
J
SON
]
[
Node
a
]
:<|>
Summary
" Tabs"
:>
FacetDocAPI
:<|>
Summary
" Tabs"
:>
FacetDocAPI
-- TODO: make the NodeId type indexed by `a`, then we no longer need the proxy.
nodeAPI
::
JSONB
a
=>
Connection
->
proxy
a
->
NodeId
->
Server
(
NodeAPI
a
)
nodeAPI
conn
p
id
=
liftIO
(
getNode
conn
id
p
)
:<|>
rename
conn
id
:<|>
postNode
conn
id
:<|>
putNode
conn
id
:<|>
deleteNode'
conn
id
:<|>
getNodesWith'
conn
id
p
:<|>
getTable
conn
id
:<|>
getChart
conn
id
:<|>
favApi
conn
id
:<|>
delDocs
conn
id
-- :<|> upload
-- :<|> query
--data FacetFormat = Table | Chart
data
FacetType
=
Docs
|
Terms
|
Sources
|
Authors
|
Trash
...
...
@@ -126,8 +186,8 @@ data FacetType = Docs | Terms | Sources | Authors | Trash
instance
FromHttpApiData
FacetType
where
parseUrlPiece
"Docs"
=
pure
Docs
parseUrlPiece
"Terms"
=
pure
Terms
parseUrlPiece
"Docs"
=
pure
Docs
parseUrlPiece
"Terms"
=
pure
Terms
parseUrlPiece
"Sources"
=
pure
Sources
parseUrlPiece
"Authors"
=
pure
Authors
parseUrlPiece
"Trash"
=
pure
Trash
...
...
@@ -141,6 +201,7 @@ instance Arbitrary FacetType
where
arbitrary
=
elements
[
minBound
..
maxBound
]
------------------------------------------------------------------------
type
FacetDocAPI
=
"table"
:>
Summary
" Table data"
:>
QueryParam
"view"
FacetType
...
...
@@ -154,6 +215,8 @@ type FacetDocAPI = "table"
:>
QueryParam
"from"
UTCTime
:>
QueryParam
"to"
UTCTime
:>
Get
'[
J
SON
]
[
FacetChart
]
:<|>
Summary
" Favorites"
:>
FavApi
:<|>
Summary
" Documents"
:>
DocsApi
-- Depending on the Type of the Node, we could post
-- New documents for a corpus
...
...
@@ -172,6 +235,7 @@ roots conn = liftIO (putStrLn ( "/user" :: Text) >> getNodesWithParentId 0 Nothi
:<|>
pure
(
panic
"not implemented yet"
)
-- TODO
------------------------------------------------------------------------
type
GraphAPI
=
Get
'[
J
SON
]
Graph
graphAPI
::
Connection
->
NodeId
->
Server
GraphAPI
graphAPI
_
_
=
liftIO
$
textFlow
(
Mono
EN
)
(
Contexts
contextText
)
...
...
@@ -189,19 +253,7 @@ type TreeAPI = Get '[JSON] (Tree NodeTree)
treeAPI
::
Connection
->
NodeId
->
Server
TreeAPI
treeAPI
=
treeDB
-- TODO: make the NodeId type indexed by `a`, then we no longer need the proxy.
nodeAPI
::
JSONB
a
=>
Connection
->
proxy
a
->
NodeId
->
Server
(
NodeAPI
a
)
nodeAPI
conn
p
id
=
liftIO
(
getNode
conn
id
p
)
:<|>
rename
conn
id
:<|>
postNode
conn
id
:<|>
putNode
conn
id
:<|>
deleteNode'
conn
id
:<|>
getNodesWith'
conn
id
p
:<|>
getTable
conn
id
:<|>
getChart
conn
id
-- :<|> upload
-- :<|> query
------------------------------------------------------------------------
-- | Check if the name is less than 255 char
--rename :: Connection -> NodeId -> Rename -> Server NodeAPI
rename
::
Connection
->
NodeId
->
RenameNode
->
Handler
[
Int
]
...
...
@@ -210,14 +262,17 @@ rename c nId (RenameNode name) = liftIO $ U.update (U.Rename nId name) c
nodesAPI
::
Connection
->
[
NodeId
]
->
Server
NodesAPI
nodesAPI
conn
ids
=
deleteNodes'
conn
ids
getTable
::
Connection
->
NodeId
->
Maybe
FacetType
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Handler
[
FacetDoc
]
getTable
::
Connection
->
NodeId
->
Maybe
FacetType
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Handler
[
FacetDoc
]
getTable
c
cId
ft
o
l
order
=
liftIO
$
case
ft
of
(
Just
Docs
)
->
runViewDocuments'
c
cId
False
o
l
order
(
Just
Trash
)
->
runViewDocuments'
c
cId
True
o
l
order
_
->
panic
"not implemented"
getChart
::
Connection
->
NodeId
->
Maybe
UTCTime
->
Maybe
UTCTime
->
Handler
[
FacetChart
]
getChart
_
_
_
_
=
undefined
-- TODO
postNode
::
Connection
->
NodeId
->
PostNode
->
Handler
[
Int
]
postNode
c
pId
(
PostNode
name
nt
)
=
liftIO
$
mk
c
nt
(
Just
pId
)
name
...
...
@@ -236,10 +291,6 @@ getNodesWith' :: JSONB a => Connection -> NodeId -> proxy a -> Maybe NodeType
getNodesWith'
conn
id
p
nodeType
offset
limit
=
liftIO
(
getNodesWith
conn
id
p
nodeType
offset
limit
)
getChart
::
Connection
->
NodeId
->
Maybe
UTCTime
->
Maybe
UTCTime
->
Handler
[
FacetChart
]
getChart
_
_
_
_
=
undefined
-- TODO
query
::
Text
->
Handler
Text
query
s
=
pure
s
...
...
src/Gargantext/Database/NodeNode.hs
View file @
38449989
...
...
@@ -96,8 +96,8 @@ instance QueryRunnerColumnDefault PGBool (Maybe Bool) where
------------------------------------------------------------------------
-- | Favorite management
nodeToFavorite
::
PGS
.
Connection
->
CorpusId
->
DocId
->
Bool
->
IO
[
PGS
.
Only
Int
]
nodeToFavorite
c
cId
dId
b
=
PGS
.
query
c
favQuery
(
b
,
cId
,
dId
)
nodeToFavorite
::
PGS
.
Connection
->
CorpusId
->
DocId
->
Bool
->
IO
[
Int
]
nodeToFavorite
c
cId
dId
b
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
PGS
.
query
c
favQuery
(
b
,
cId
,
dId
)
where
favQuery
::
PGS
.
Query
favQuery
=
[
sql
|
UPDATE nodes_nodes SET favorite = ?
...
...
@@ -105,8 +105,9 @@ nodeToFavorite c cId dId b = PGS.query c favQuery (b,cId,dId)
RETURNING node2_id;
|]
nodesToFavorite
::
PGS
.
Connection
->
[(
CorpusId
,
DocId
,
Bool
)]
->
IO
[
PGS
.
Only
Int
]
nodesToFavorite
c
inputData
=
PGS
.
query
c
trashQuery
(
PGS
.
Only
$
Values
fields
inputData
)
nodesToFavorite
::
PGS
.
Connection
->
[(
CorpusId
,
DocId
,
Bool
)]
->
IO
[
Int
]
nodesToFavorite
c
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
PGS
.
query
c
trashQuery
(
PGS
.
Only
$
Values
fields
inputData
)
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
[
"int4"
,
"int4"
,
"bool"
]
trashQuery
::
PGS
.
Query
...
...
@@ -131,8 +132,9 @@ nodeToTrash c cId dId b = PGS.query c trashQuery (b,cId,dId)
|]
-- | Trash Massive
nodesToTrash
::
PGS
.
Connection
->
[(
CorpusId
,
DocId
,
Bool
)]
->
IO
[
PGS
.
Only
Int
]
nodesToTrash
c
inputData
=
PGS
.
query
c
trashQuery
(
PGS
.
Only
$
Values
fields
inputData
)
nodesToTrash
::
PGS
.
Connection
->
[(
CorpusId
,
DocId
,
Bool
)]
->
IO
[
Int
]
nodesToTrash
c
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
PGS
.
query
c
trashQuery
(
PGS
.
Only
$
Values
fields
inputData
)
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
[
"int4"
,
"int4"
,
"bool"
]
trashQuery
::
PGS
.
Query
...
...
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