Skip to content
Snippets Groups Projects
Commit ec0795ab authored by thijsheijden's avatar thijsheijden
Browse files

Moved domain specific entities into entity package

parent 93df1490
No related branches found
No related tags found
No related merge requests found
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
}
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)
}
......@@ -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.nodeList
queryResult["edges"] = listContainer.edgeList
queryResult["nodes"] = listContainer.NodeList
queryResult["edges"] = listContainer.EdgeList
//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).nodeList = append((*listContainer).nodeList, parseNode(vertexDoc))
(*listContainer).NodeList = append((*listContainer).NodeList, parseNode(vertexDoc))
}
for _, edge := range edges {
edgeDoc := edge.(map[string]interface{})
(*listContainer).edgeList = append((*listContainer).edgeList, parseEdge(edgeDoc))
(*listContainer).EdgeList = append((*listContainer).EdgeList, 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"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment