From 543c2636c3f031b55f9d0e68dbbf9428b1628595 Mon Sep 17 00:00:00 2001 From: Joris <j.r.j.lelieveld@students.uu.nl> Date: Fri, 16 Apr 2021 16:16:43 +0200 Subject: [PATCH] Added some comments --- internal/usecases/request/request.go | 56 +++++++++------------ internal/usecases/request/requestStructs.go | 27 ++++++++++ 2 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 internal/usecases/request/requestStructs.go diff --git a/internal/usecases/request/request.go b/internal/usecases/request/request.go index 3621fc0..e39c949 100644 --- a/internal/usecases/request/request.go +++ b/internal/usecases/request/request.go @@ -13,37 +13,18 @@ import ( "github.com/arangodb/go-driver/http" ) -// Service is a struct used to store this use case in -type Service struct { -} - -// NewService creates a new instantion of this use case -func NewService() *Service { - return &Service{} -} - -// 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 -} - -type arangoResult struct { - vertices []Document - edges []Document -} - //attr interface{} //map[1 , 2 , 3 map [ .. ]] -// SendAQLQuery send AQL string query to database and returns a JSON object in a general format +/* +SendAQLQuery send AQL string query to database and returns a JSON object in a general format + +Parameters: AQLQuery is a string containing the query that will be send to the database + +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) { var queryResult = make(map[string][]Document) conn, err := http.NewConnection(http.ConnectionConfig{ @@ -78,6 +59,7 @@ func (s *Service) SendAQLQuery(AQLQuery string) (*map[string][]Document, error) } defer cursor.Close() + //Loop through the resulting documents listContainer := ListContainer{} for { var doc map[string][]interface{} @@ -100,7 +82,13 @@ func (s *Service) SendAQLQuery(AQLQuery string) (*map[string][]Document, error) return &queryResult, nil } -//Resultaat: [ { vertices : [], edges : [] } ] +/* parseResult takes the result of the query and translates this to two lists: a nodelist and an edgelist, stored in a listcontainer + +Parameters: doc is the document with the nodes and vertices that came back from the database, +listContainer is a struct containing the nodelist and edgelist that will be returned to the frontend + +Return: Nothing because the result is stored in the listContainer +*/ func parseResult(doc map[string][]interface{}, listContainer *ListContainer) { vertices := doc["vertices"] edges := doc["edges"] @@ -120,9 +108,11 @@ func parseResult(doc map[string][]interface{}, listContainer *ListContainer) { } } -// parseResult takes the result of the query and translates this to two lists: a nodelist and an edgelist, stored in a listcontainer +/* parseEdge parses the data of an edge to an output-friendly format +Parameters: d is a single entry of an edge -// parseEdge parses the data of an edge to an output-friendly format +Return: a document with almost the same structure as before, but the attributes are grouped +*/ func parseEdge(d map[string]interface{}) Document { doc := d //.(map[string]interface{}) @@ -154,7 +144,11 @@ func writeJSON(queryResult map[string][]Document) { _ = ioutil.WriteFile("result.json", file, 0644) } -// parseNode parses the data of a node to an output-friendly format +/* parseEdge parses the data of a node to an output-friendly format +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 { doc := d //.(map[string]interface{}) diff --git a/internal/usecases/request/requestStructs.go b/internal/usecases/request/requestStructs.go new file mode 100644 index 0000000..7a3ccfd --- /dev/null +++ b/internal/usecases/request/requestStructs.go @@ -0,0 +1,27 @@ +package request + +// Service is a struct used to store this use case in +type Service struct { +} + +// NewService creates a new instantion of this use case +func NewService() *Service { + return &Service{} +} + +// 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 +} + +type arangoResult struct { + vertices []Document + edges []Document +} -- GitLab