Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
query-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
Microservices
query-service
Commits
ec0795ab
Commit
ec0795ab
authored
4 years ago
by
thijsheijden
Browse files
Options
Downloads
Patches
Plain Diff
Moved domain specific entities into entity package
parent
93df1490
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
internal/entity/document.go
+13
-0
13 additions, 0 deletions
internal/entity/document.go
internal/usecases/request/interface.go
+3
-1
3 additions, 1 deletion
internal/usecases/request/interface.go
internal/usecases/request/request.go
+14
-13
14 additions, 13 deletions
internal/usecases/request/request.go
with
30 additions
and
14 deletions
internal/entity/document.go
0 → 100644
+
13
−
0
View file @
ec0795ab
package
entity
// Document with Empty struct to retrieve all data from the DB Document
type
Document
map
[
string
]
interface
{}
// GeneralFormat with Empty struct to retrieve all data from the DB Document
type
GeneralFormat
map
[
string
][]
Document
// ListContainer is a struct that keeps track of the nodes and edges that need to be returned
type
ListContainer
struct
{
NodeList
[]
Document
EdgeList
[]
Document
}
This diff is collapsed.
Click to expand it.
internal/usecases/request/interface.go
+
3
−
1
View file @
ec0795ab
package
request
import
"query-service/internal/entity"
// UseCase is an interface describing the request usecases
type
UseCase
interface
{
SendAQLQuery
(
query
string
)
(
*
map
[
string
][]
Document
,
error
)
SendAQLQuery
(
query
string
)
(
*
map
[
string
][]
entity
.
Document
,
error
)
}
This diff is collapsed.
Click to expand it.
internal/usecases/request/request.go
+
14
−
13
View file @
ec0795ab
...
...
@@ -5,6 +5,7 @@ import (
"crypto/tls"
"log"
"os"
"query-service/internal/entity"
"encoding/json"
"io/ioutil"
...
...
@@ -25,10 +26,10 @@ Parameters: AQLQuery is a string containing the query that will be send to the d
Return: a map with two entries: "nodes" with a list of vertices/nodes and "edges" with a list of edges
that will be returned to the frontend
*/
func
(
s
*
Service
)
SendAQLQuery
(
AQLQuery
string
)
(
*
map
[
string
][]
Document
,
error
)
{
func
(
s
*
Service
)
SendAQLQuery
(
AQLQuery
string
)
(
*
map
[
string
][]
entity
.
Document
,
error
)
{
// Get ArangoDB url from environment variable
arangoURL
:=
os
.
Getenv
(
"ARANGO_HOST"
)
var
queryResult
=
make
(
map
[
string
][]
Document
)
var
queryResult
=
make
(
map
[
string
][]
entity
.
Document
)
conn
,
err
:=
http
.
NewConnection
(
http
.
ConnectionConfig
{
Endpoints
:
[]
string
{
arangoURL
},
TLSConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
...
...
@@ -62,7 +63,7 @@ func (s *Service) SendAQLQuery(AQLQuery string) (*map[string][]Document, error)
defer
cursor
.
Close
()
//Loop through the resulting documents
listContainer
:=
ListContainer
{}
listContainer
:=
entity
.
ListContainer
{}
for
{
var
doc
map
[
string
][]
interface
{}
_
,
err
:=
cursor
.
ReadDocument
(
ctx
,
&
doc
)
...
...
@@ -76,8 +77,8 @@ func (s *Service) SendAQLQuery(AQLQuery string) (*map[string][]Document, error)
parseResult
(
doc
,
&
listContainer
)
}
queryResult
[
"nodes"
]
=
listContainer
.
n
odeList
queryResult
[
"edges"
]
=
listContainer
.
e
dgeList
queryResult
[
"nodes"
]
=
listContainer
.
N
odeList
queryResult
[
"edges"
]
=
listContainer
.
E
dgeList
//writeJSON(queryResult)
//file, err := json.MarshalIndent(queryResult, "", " ")
...
...
@@ -91,20 +92,20 @@ listContainer is a struct containing the nodelist and edgelist that will be retu
Return: Nothing because the result is stored in the listContainer
*/
func
parseResult
(
doc
map
[
string
][]
interface
{},
listContainer
*
ListContainer
)
{
func
parseResult
(
doc
map
[
string
][]
interface
{},
listContainer
*
entity
.
ListContainer
)
{
vertices
:=
doc
[
"vertices"
]
edges
:=
doc
[
"edges"
]
for
_
,
vertex
:=
range
vertices
{
vertexDoc
:=
vertex
.
(
map
[
string
]
interface
{})
(
*
listContainer
)
.
n
odeList
=
append
((
*
listContainer
)
.
n
odeList
,
parseNode
(
vertexDoc
))
(
*
listContainer
)
.
N
odeList
=
append
((
*
listContainer
)
.
N
odeList
,
parseNode
(
vertexDoc
))
}
for
_
,
edge
:=
range
edges
{
edgeDoc
:=
edge
.
(
map
[
string
]
interface
{})
(
*
listContainer
)
.
e
dgeList
=
append
((
*
listContainer
)
.
e
dgeList
,
parseEdge
(
edgeDoc
))
(
*
listContainer
)
.
E
dgeList
=
append
((
*
listContainer
)
.
E
dgeList
,
parseEdge
(
edgeDoc
))
}
}
...
...
@@ -113,10 +114,10 @@ Parameters: d is a single entry of an edge
Return: a document with almost the same structure as before, but the attributes are grouped
*/
func
parseEdge
(
d
map
[
string
]
interface
{})
Document
{
func
parseEdge
(
d
map
[
string
]
interface
{})
entity
.
Document
{
doc
:=
d
//.(map[string]interface{})
data
:=
make
(
Document
)
data
:=
make
(
entity
.
Document
)
data
[
"_id"
]
=
doc
[
"_id"
]
delete
(
doc
,
"_id"
)
data
[
"_key"
]
=
doc
[
"_key"
]
...
...
@@ -138,7 +139,7 @@ func parseEdge(d map[string]interface{}) Document {
}
// writeJSON writes a json file for testing purposes
func
writeJSON
(
queryResult
map
[
string
][]
Document
)
{
func
writeJSON
(
queryResult
map
[
string
][]
entity
.
Document
)
{
file
,
_
:=
json
.
MarshalIndent
(
queryResult
,
""
,
" "
)
_
=
ioutil
.
WriteFile
(
"result.json"
,
file
,
0644
)
...
...
@@ -149,10 +150,10 @@ Parameters: d is a single entry of an node
Return: a document with almost the same structure as before, but the attributes are grouped
*/
func
parseNode
(
d
map
[
string
]
interface
{})
Document
{
func
parseNode
(
d
map
[
string
]
interface
{})
entity
.
Document
{
doc
:=
d
//.(map[string]interface{})
data
:=
make
(
Document
)
data
:=
make
(
entity
.
Document
)
data
[
"_id"
]
=
doc
[
"_id"
]
delete
(
doc
,
"_id"
)
data
[
"_key"
]
=
doc
[
"_key"
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment