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
871b48ee
Commit
871b48ee
authored
Oct 22, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] refactor nodeApi.
parent
58cdb74f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
82 deletions
+87
-82
API.hs
src/Gargantext/API.hs
+1
-0
Node.hs
src/Gargantext/API/Node.hs
+85
-81
Facet.hs
src/Gargantext/Database/Facet.hs
+1
-1
No files found.
src/Gargantext/API.hs
View file @
871b48ee
...
...
@@ -213,6 +213,7 @@ type GargAPI' =
-- 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 @
871b48ee
...
...
@@ -69,17 +69,75 @@ import Gargantext.Text.Terms (TermType(..))
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
-------------------------------------------------------------------
-- | Node API Types management
-- | TODO : access by admin only
type
NodesAPI
=
Delete
'[
J
SON
]
Int
-- | Delete Nodes
-- Be careful: really delete nodes
-- Access by admin only
nodesAPI
::
Connection
->
[
NodeId
]
->
Server
NodesAPI
nodesAPI
conn
ids
=
deleteNodes'
conn
ids
------------------------------------------------------------------------
-- | TODO: access by admin only
-- To manager the Users roots
type
Roots
=
Get
'[
J
SON
]
[
Node
Value
]
:<|>
Post
'[
J
SON
]
Int
-- TODO
:<|>
Put
'[
J
SON
]
Int
-- TODO
:<|>
Delete
'[
J
SON
]
Int
-- TODO
type
NodesAPI
=
Delete
'[
J
SON
]
Int
-- | TODO: access by admin only
roots
::
Connection
->
Server
Roots
roots
conn
=
liftIO
(
putStrLn
(
"/user"
::
Text
)
>>
getNodesWithParentId
0
Nothing
conn
)
:<|>
pure
(
panic
"not implemented yet"
)
-- TODO
:<|>
pure
(
panic
"not implemented yet"
)
-- TODO
:<|>
pure
(
panic
"not implemented yet"
)
-- TODO
-------------------------------------------------------------------
-- | Node API Types management
-- TODO : access by users
type
NodeAPI
a
=
Get
'[
J
SON
]
(
Node
a
)
:<|>
"rename"
:>
RenameApi
:<|>
PostNodeApi
:<|>
Put
'[
J
SON
]
Int
:<|>
Delete
'[
J
SON
]
Int
:<|>
"children"
:>
ChildrenApi
a
:<|>
"table"
:>
TableApi
:<|>
"chart"
:>
ChartApi
:<|>
"favorites"
:>
FavApi
:<|>
"documents"
:>
DocsApi
type
RenameApi
=
Summary
" RenameNode Node"
:>
ReqBody
'[
J
SON
]
RenameNode
:>
Put
'[
J
SON
]
[
Int
]
type
PostNodeApi
=
Summary
" PostNode Node with ParentId as {id}"
:>
ReqBody
'[
J
SON
]
PostNode
:>
Post
'[
J
SON
]
[
Int
]
type
ChildrenApi
a
=
Summary
" Summary children"
:>
QueryParam
"type"
NodeType
:>
QueryParam
"offset"
Int
:>
QueryParam
"limit"
Int
:>
Get
'[
J
SON
]
[
Node
a
]
------------------------------------------------------------------------
-- 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
RenameNode
=
RenameNode
{
r_name
::
Text
}
deriving
(
Generic
)
...
...
@@ -89,7 +147,6 @@ instance ToJSON RenameNode
instance
ToSchema
RenameNode
instance
Arbitrary
RenameNode
where
arbitrary
=
elements
[
RenameNode
"test"
]
------------------------------------------------------------------------
data
PostNode
=
PostNode
{
pn_name
::
Text
...
...
@@ -103,7 +160,7 @@ instance Arbitrary PostNode where
arbitrary
=
elements
[
PostNode
"Node test"
NodeCorpus
]
------------------------------------------------------------------------
type
DocsApi
=
Summary
"Move to trash"
type
DocsApi
=
Summary
"
Docs :
Move to trash"
:>
ReqBody
'[
J
SON
]
Documents
:>
Delete
'[
J
SON
]
[
Int
]
...
...
@@ -119,10 +176,10 @@ delDocs c cId ds = liftIO $ nodesToTrash c
$
map
(
\
n
->
(
cId
,
n
,
True
))
$
documents
ds
------------------------------------------------------------------------
type
FavApi
=
Summary
"
Label as Favorites
"
type
FavApi
=
Summary
"
Favorites label
"
:>
ReqBody
'[
J
SON
]
Favorites
:>
Put
'[
J
SON
]
[
Int
]
:<|>
Summary
"
Unlabel as Favorites
"
:<|>
Summary
"
Favorites unlabel
"
:>
ReqBody
'[
J
SON
]
Favorites
:>
Delete
'[
J
SON
]
[
Int
]
...
...
@@ -146,81 +203,40 @@ favApi :: Connection -> CorpusId -> (Favorites -> Handler [Int])
favApi
c
cId
=
putFav
c
cId
:<|>
delFav
c
cId
------------------------------------------------------------------------
type
NodeAPI
a
=
Get
'[
J
SON
]
(
Node
a
)
:<|>
"rename"
:>
Summary
" RenameNode Node"
:>
ReqBody
'[
J
SON
]
RenameNode
:>
Put
'[
J
SON
]
[
Int
]
:<|>
Summary
" PostNode Node with ParentId as {id}"
:>
ReqBody
'[
J
SON
]
PostNode
:>
Post
'[
J
SON
]
[
Int
]
:<|>
Put
'[
J
SON
]
Int
:<|>
Delete
'[
J
SON
]
Int
:<|>
"children"
:>
Summary
" Summary children"
:>
QueryParam
"type"
NodeType
:>
QueryParam
"offset"
Int
:>
QueryParam
"limit"
Int
:>
Get
'[
J
SON
]
[
Node
a
]
:<|>
Summary
" Tabs"
:>
FacetDocAPI
-- How TODO ?
:<|>
"favorites"
:>
Summary
" Favorites"
:>
FavApi
:<|>
"documents"
:>
Summary
" Documents"
:>
DocsApi
-- 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
Facet
Type
=
Docs
|
Terms
|
Sources
|
Authors
|
Trash
data
Tab
Type
=
Docs
|
Terms
|
Sources
|
Authors
|
Trash
deriving
(
Generic
,
Enum
,
Bounded
)
instance
FromHttpApiData
Facet
Type
instance
FromHttpApiData
Tab
Type
where
parseUrlPiece
"Docs"
=
pure
Docs
parseUrlPiece
"Terms"
=
pure
Terms
parseUrlPiece
"Sources"
=
pure
Sources
parseUrlPiece
"Authors"
=
pure
Authors
parseUrlPiece
"Trash"
=
pure
Trash
parseUrlPiece
_
=
Left
"Unexpected value of
Facet
Type"
parseUrlPiece
_
=
Left
"Unexpected value of
Tab
Type"
instance
ToParamSchema
Facet
Type
instance
ToJSON
Facet
Type
instance
FromJSON
Facet
Type
instance
ToSchema
Facet
Type
instance
Arbitrary
Facet
Type
instance
ToParamSchema
Tab
Type
instance
ToJSON
Tab
Type
instance
FromJSON
Tab
Type
instance
ToSchema
Tab
Type
instance
Arbitrary
Tab
Type
where
arbitrary
=
elements
[
minBound
..
maxBound
]
------------------------------------------------------------------------
type
FacetDocAPI
=
"table"
:>
Summary
" Table data"
:>
QueryParam
"view"
FacetType
:>
QueryParam
"offset"
Int
:>
QueryParam
"limit"
Int
:>
QueryParam
"order"
OrderBy
:>
Get
'[
J
SON
]
[
FacetDoc
]
:<|>
"chart"
:>
Summary
" Chart data"
:>
QueryParam
"from"
UTCTime
:>
QueryParam
"to"
UTCTime
:>
Get
'[
J
SON
]
[
FacetChart
]
-- :<|> "favorites" :> Summary " Favorites" :> FavApi
-- :<|> "documents" :> Summary " Documents" :> DocsApi
type
TableApi
=
Summary
" Table API"
:>
QueryParam
"view"
TabType
:>
QueryParam
"offset"
Int
:>
QueryParam
"limit"
Int
:>
QueryParam
"order"
OrderBy
:>
Get
'[
J
SON
]
[
FacetDoc
]
type
ChartApi
=
Summary
" Chart API"
:>
QueryParam
"from"
UTCTime
:>
QueryParam
"to"
UTCTime
:>
Get
'[
J
SON
]
[
FacetChart
]
-- Depending on the Type of the Node, we could post
-- New documents for a corpus
...
...
@@ -231,13 +247,6 @@ type FacetDocAPI = "table"
-- :<|> "query" :> Capture "string" Text :> Get '[JSON] Text
-- | Node API functions
roots
::
Connection
->
Server
Roots
roots
conn
=
liftIO
(
putStrLn
(
"/user"
::
Text
)
>>
getNodesWithParentId
0
Nothing
conn
)
:<|>
pure
(
panic
"not implemented yet"
)
-- TODO
:<|>
pure
(
panic
"not implemented yet"
)
-- TODO
:<|>
pure
(
panic
"not implemented yet"
)
-- TODO
------------------------------------------------------------------------
type
GraphAPI
=
Get
'[
J
SON
]
Graph
graphAPI
::
Connection
->
NodeId
->
Server
GraphAPI
...
...
@@ -258,14 +267,10 @@ treeAPI = treeDB
------------------------------------------------------------------------
-- | Check if the name is less than 255 char
--rename :: Connection -> NodeId -> Rename -> Server NodeAPI
rename
::
Connection
->
NodeId
->
RenameNode
->
Handler
[
Int
]
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
getTable
::
Connection
->
NodeId
->
Maybe
TabType
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Handler
[
FacetDoc
]
getTable
c
cId
ft
o
l
order
=
liftIO
$
case
ft
of
...
...
@@ -294,7 +299,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
)
query
::
Text
->
Handler
Text
query
s
=
pure
s
...
...
src/Gargantext/Database/Facet.hs
View file @
871b48ee
...
...
@@ -23,7 +23,7 @@ Portability : POSIX
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
------------------------------------------------------------------------
module
Gargantext.Database.Facet
module
Gargantext.Database.Facet
where
------------------------------------------------------------------------
...
...
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