diff --git a/internal/usecases/request/request.go b/internal/usecases/request/request.go index 3621fc0774ffc567c50806f6887b4a03d18969cb..e39c949a904a2ceb1147f2ade7a7c64a8a561f9c 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 0000000000000000000000000000000000000000..7a3ccfdd87a8b65f3514e6b3b02b7ee7e958568f --- /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 +}