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
141
Issues
141
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
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
1b07704e
Commit
1b07704e
authored
Apr 30, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DB/Errors] DoesNotExist Node error (todo remove useless errors type).
parent
217e984e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 deletions
+28
-12
Node.hs
src/Gargantext/Database/Query/Table/Node.hs
+25
-12
Error.hs
src/Gargantext/Database/Query/Table/Node/Error.hs
+3
-0
No files found.
src/Gargantext/Database/Query/Table/Node.hs
View file @
1b07704e
...
...
@@ -54,9 +54,9 @@ queryNodeSearchTable = queryTable nodeTableSearch
selectNode
::
Column
PGInt4
->
Query
NodeRead
selectNode
id
=
proc
()
->
do
row
<-
queryNodeTable
-<
()
row
<-
queryNodeTable
-<
()
restrict
-<
_node_id
row
.==
id
returnA
-<
row
returnA
-<
row
runGetNodes
::
Query
NodeRead
->
Cmd
err
[
Node
HyperdataAny
]
runGetNodes
=
runOpaQuery
...
...
@@ -67,7 +67,7 @@ runGetNodes = runOpaQuery
-- Favorites (Bool), node_ngrams
selectNodesWith
::
ParentId
->
Maybe
NodeType
->
Maybe
Offset
->
Maybe
Limit
->
Query
NodeRead
selectNodesWith
parentId
maybeNodeType
maybeOffset
maybeLimit
=
selectNodesWith
parentId
maybeNodeType
maybeOffset
maybeLimit
=
--offset' maybeOffset $ limit' maybeLimit $ orderBy (asc (hyperdataDocument_Publication_date . node_hyperdata)) $ selectNodesWith' parentId typeId
limit'
maybeLimit
$
offset'
maybeOffset
$
orderBy
(
asc
_node_id
)
...
...
@@ -154,11 +154,14 @@ getNodeWith nId _ = do
<$>
runOpaQuery
(
limit
1
$
selectNode
(
pgNodeId
nId
))
getNodePhylo
::
NodeId
->
Cmd
err
(
Node
HyperdataPhylo
)
getNodePhylo
::
HasNodeError
err
=>
NodeId
->
Cmd
err
(
Node
HyperdataPhylo
)
getNodePhylo
nId
=
do
fromMaybe
(
error
$
"Node Phylo does not exist: "
<>
show
nId
)
.
headMay
<$>
runOpaQuery
(
limit
1
$
selectNode
(
pgNodeId
nId
))
res
<-
headMay
<$>
runOpaQuery
(
selectNode
(
pgNodeId
nId
))
case
res
of
Nothing
->
nodeError
(
DoesNotExist
nId
)
Just
r
->
pure
r
getNodesWithType
::
Column
PGInt4
->
Cmd
err
[
Node
HyperdataDocument
]
getNodesWithType
=
runOpaQuery
.
selectNodesWithType
...
...
@@ -293,15 +296,20 @@ nodePhyloW maybeName maybePhylo pId = node NodePhylo name graph (Just pId)
name
=
maybe
"Phylo"
identity
maybeName
graph
=
maybe
arbitraryPhylo
identity
maybePhylo
------------------------------------------------------------------------
arbitraryDashboard
::
HyperdataDashboard
arbitraryDashboard
=
HyperdataDashboard
(
Just
"Preferences"
)
[]
------------------------------------------------------------------------
node
::
(
ToJSON
a
,
Hyperdata
a
)
=>
NodeType
->
Name
->
a
->
Maybe
ParentId
->
UserId
->
NodeWrite
node
::
(
ToJSON
a
,
Hyperdata
a
)
=>
NodeType
->
Name
->
a
->
Maybe
ParentId
->
UserId
->
NodeWrite
node
nodeType
name
hyperData
parentId
userId
=
Node
Nothing
Node
Nothing
(
pgInt4
typeId
)
(
pgInt4
userId
)
(
pgNodeId
<$>
parentId
)
...
...
@@ -355,7 +363,8 @@ data Node' = Node' { _n_type :: NodeType
}
deriving
(
Show
)
mkNodes
::
[
NodeWrite
]
->
Cmd
err
Int64
mkNodes
ns
=
mkCmd
$
\
conn
->
runInsert_
conn
$
Insert
nodeTable
ns
rCount
Nothing
mkNodes
ns
=
mkCmd
$
\
conn
->
runInsert_
conn
$
Insert
nodeTable
ns
rCount
Nothing
mkNodeR
::
[
NodeWrite
]
->
Cmd
err
[
NodeId
]
mkNodeR
ns
=
mkCmd
$
\
conn
->
runInsert_
conn
$
Insert
nodeTable
ns
(
rReturning
_node_id
)
Nothing
...
...
@@ -365,7 +374,11 @@ mkNodeR ns = mkCmd $ \conn -> runInsert_ conn $ Insert nodeTable ns (rReturning
data
NewNode
=
NewNode
{
_newNodeId
::
NodeId
,
_newNodeChildren
::
[
NodeId
]
}
postNode
::
HasNodeError
err
=>
UserId
->
Maybe
ParentId
->
Node'
->
Cmd
err
NewNode
postNode
::
HasNodeError
err
=>
UserId
->
Maybe
ParentId
->
Node'
->
Cmd
err
NewNode
postNode
uid
pid
(
Node'
nt
txt
v
[]
)
=
do
pids
<-
mkNodeR
[
node2table
uid
pid
(
Node'
nt
txt
v
[]
)]
...
...
src/Gargantext/Database/Query/Table/Node/Error.hs
View file @
1b07704e
...
...
@@ -26,6 +26,7 @@ Portability : POSIX
module
Gargantext.Database.Query.Table.Node.Error
where
import
Gargantext.Database.Admin.Types.Node
(
NodeId
)
import
Control.Lens
(
Prism
'
,
(
#
),
(
^?
))
import
Control.Monad.Error.Class
(
MonadError
(
..
))
import
Gargantext.Prelude
hiding
(
sum
,
head
)
...
...
@@ -43,6 +44,7 @@ data NodeError = NoListFound
|
NegativeId
|
NotImplYet
|
ManyNodeUsers
|
DoesNotExist
NodeId
instance
Show
NodeError
where
...
...
@@ -58,6 +60,7 @@ instance Show NodeError
show
NotImplYet
=
"Not implemented yet"
show
ManyParents
=
"Too many parents"
show
ManyNodeUsers
=
"Many userNode/user"
show
(
DoesNotExist
n
)
=
"Node does not exist"
<>
show
n
class
HasNodeError
e
where
_NodeError
::
Prism'
e
NodeError
...
...
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