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
92b9a230
Commit
92b9a230
authored
Jan 22, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TYPES] Node Hyperdata for Json | Markdown fields.
parent
a3cd87ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
21 deletions
+66
-21
Node.hs
src/Gargantext/API/Node.hs
+6
-8
Node.hs
src/Gargantext/Database/Types/Node.hs
+60
-13
No files found.
src/Gargantext/API/Node.hs
View file @
92b9a230
...
...
@@ -121,7 +121,7 @@ roots = (liftIO (putStrLn ( "/user" :: Text)) >> getNodesWithParentId 0 Nothing)
type
NodeAPI
a
=
Get
'[
J
SON
]
(
Node
a
)
:<|>
"rename"
:>
RenameApi
:<|>
PostNodeApi
-- TODO move to children POST
:<|>
Put
'[
J
SON
]
Int
:<|>
ReqBody
'[
J
SON
]
a
:>
Put
'[
J
SON
]
Int
:<|>
Delete
'[
J
SON
]
Int
:<|>
"children"
:>
ChildrenApi
a
...
...
@@ -174,14 +174,14 @@ nodeNodeAPI p uId cId nId = withAccess (Proxy :: Proxy (NodeNodeAPI a)) Proxy uI
------------------------------------------------------------------------
-- TODO: make the NodeId type indexed by `a`, then we no longer need the proxy.
nodeAPI
::
forall
proxy
a
.
(
JSONB
a
,
ToJSON
a
)
=>
proxy
a
->
UserId
->
NodeId
->
GargServer
(
NodeAPI
a
)
nodeAPI
::
forall
proxy
a
.
(
JSONB
a
,
FromJSON
a
,
ToJSON
a
)
=>
proxy
a
->
UserId
->
NodeId
->
GargServer
(
NodeAPI
a
)
nodeAPI
p
uId
id
=
withAccess
(
Proxy
::
Proxy
(
NodeAPI
a
))
Proxy
uId
(
PathNode
id
)
nodeAPI'
where
nodeAPI'
::
GargServer
(
NodeAPI
a
)
nodeAPI'
=
getNodeWith
id
p
:<|>
rename
id
:<|>
postNode
uId
id
:<|>
putNode
id
p
:<|>
putNode
id
:<|>
deleteNodeApi
id
:<|>
getChildren
id
p
...
...
@@ -337,11 +337,9 @@ postNode uId pId (PostNode nodeName nt) = do
let
uId'
=
nodeUser
^.
node_userId
mkNodeWithParent
nt
(
Just
pId
)
uId'
nodeName
putNode
::
forall
err
proxy
a
.
(
HasNodeError
err
,
JSONB
a
,
ToJSON
a
)
putNode
::
forall
err
a
.
(
HasNodeError
err
,
JSONB
a
,
ToJSON
a
)
=>
NodeId
->
proxy
a
->
a
->
Cmd
err
Int
putNode
n
h
=
do
n
<-
fromIntegral
<$>
updateHyperdata
n
h
pure
n
putNode
n
h
=
fromIntegral
<$>
updateHyperdata
n
h
-------------------------------------------------------------
src/Gargantext/Database/Types/Node.hs
View file @
92b9a230
...
...
@@ -293,25 +293,70 @@ instance ToSchema Resource where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"resource_"
)
------------------------------------------------------------------------
data
HyperdataUser
=
HyperdataUser
{
hyperdataUser_language
::
Maybe
Text
data
HyperdataUser
=
HyperdataUser
{
hyperdataUser_language
::
!
(
Maybe
Text
)
}
deriving
(
Show
,
Generic
)
$
(
deriveJSON
(
unPrefix
"hyperdataUser_"
)
''
H
yperdataUser
)
instance
Hyperdata
HyperdataUser
------------------------------------------------------------------------
data
HyperdataFolder
=
HyperdataFolder
{
hyperdataFolder_desc
::
Maybe
Text
data
HyperdataFolder
=
HyperdataFolder
{
hyperdataFolder_desc
::
!
(
Maybe
Text
)
}
deriving
(
Show
,
Generic
)
$
(
deriveJSON
(
unPrefix
"hyperdataFolder_"
)
''
H
yperdataFolder
)
instance
Hyperdata
HyperdataFolder
------------------------------------------------------------------------
data
HyperdataCorpus
=
HyperdataCorpus
{
hyperdataCorpus_title
::
!
(
Maybe
Text
)
,
hyperdataCorpus_desc
::
!
(
Maybe
Text
)
,
hyperdataCorpus_query
::
!
(
Maybe
Text
)
,
hyperdataCorpus_authors
::
!
(
Maybe
Text
)
,
hyperdataCorpus_resources
::
!
(
Maybe
[
Resource
])
}
deriving
(
Show
,
Generic
)
$
(
deriveJSON
(
unPrefix
"hyperdataCorpus_"
)
''
H
yperdataCorpus
)
data
CodeType
=
JSON
|
Markdown
deriving
(
Generic
)
instance
ToJSON
CodeType
instance
FromJSON
CodeType
instance
ToSchema
CodeType
------------------------------------------------------------------------
data
CorpusField
=
MarkdownField
{
_cf_text
::
!
Text
}
|
JsonField
{
_cf_title
::
!
Text
,
_cf_desc
::
!
Text
,
_cf_query
::
!
Text
,
_cf_authors
::
!
Text
,
_cf_resources
::
!
[
Resource
]
}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"_cf_"
)
''
C
orpusField
)
$
(
makeLenses
''
C
orpusField
)
defaultCorpusField
::
CorpusField
defaultCorpusField
=
MarkdownField
"#title"
instance
ToSchema
CorpusField
where
declareNamedSchema
proxy
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_cf_"
)
proxy
&
mapped
.
schema
.
description
?~
"CorpusField"
&
mapped
.
schema
.
example
?~
toJSON
defaultCorpusField
------------------------------------------------------------------------
data
HyperdataField
a
=
HyperdataField
{
_hf_type
::
!
CodeType
,
_hf_name
::
!
Text
,
_hf_data
::
!
a
}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"_hf_"
)
''
H
yperdataField
)
$
(
makeLenses
''
H
yperdataField
)
defaultHyperdataField
::
HyperdataField
CorpusField
defaultHyperdataField
=
HyperdataField
Markdown
"name"
defaultCorpusField
instance
(
ToSchema
a
)
=>
ToSchema
(
HyperdataField
a
)
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_hf_"
)
-- & mapped.schema.description ?~ "HyperdataField"
-- & mapped.schema.example ?~ toJSON defaultHyperdataField
------------------------------------------------------------------------
data
HyperdataCorpus
=
HyperdataCorpus
{
_hc_fields
::
!
[
HyperdataField
CorpusField
]
}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"_hc_"
)
''
H
yperdataCorpus
)
$
(
makeLenses
''
H
yperdataCorpus
)
instance
Hyperdata
HyperdataCorpus
...
...
@@ -319,7 +364,9 @@ corpusExample :: ByteString
corpusExample
=
""
-- TODO
defaultCorpus
::
HyperdataCorpus
defaultCorpus
=
(
HyperdataCorpus
(
Just
"Title"
)
(
Just
"Descr"
)
(
Just
"Bool query"
)
(
Just
"Authors"
)
Nothing
)
defaultCorpus
=
HyperdataCorpus
[
HyperdataField
JSON
"Mandatory fields"
(
JsonField
"Title"
"Descr"
"Bool query"
"Authors"
[]
)
,
HyperdataField
Markdown
"Optional Text"
(
MarkdownField
"#title
\n
##subtitle"
)
]
hyperdataCorpus
::
HyperdataCorpus
hyperdataCorpus
=
case
decode
corpusExample
of
...
...
@@ -477,7 +524,7 @@ data NodePolySearch id typename userId
,
_ns_parentId
::
parentId
,
_ns_name
::
name
,
_ns_date
::
date
,
_ns_hyperdata
::
hyperdata
,
_ns_search
::
search
}
deriving
(
Show
,
Generic
)
...
...
@@ -527,8 +574,8 @@ docExample = "{\"doi\":\"sdfds\",\"publication_day\":6,\"language_iso2\":\"en\",
instance
ToSchema
HyperdataCorpus
where
declareNamedSchema
proxy
=
genericDeclareNamedSchema
(
unPrefixSwagger
"
hyperdataCorpus
_"
)
proxy
&
mapped
.
schema
.
description
?~
"
a c
orpus"
genericDeclareNamedSchema
(
unPrefixSwagger
"
_hc
_"
)
proxy
&
mapped
.
schema
.
description
?~
"
C
orpus"
&
mapped
.
schema
.
example
?~
toJSON
hyperdataCorpus
instance
ToSchema
HyperdataAnnuaire
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