From 082d9e2b781e745379f4a3b010d9ac94b1ece467 Mon Sep 17 00:00:00 2001
From: Samed <sbalcioglu@graphpolaris.com>
Date: Tue, 30 Jul 2024 14:33:12 +0200
Subject: [PATCH] Test commit

---
 cmd/query-service/main.go | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/cmd/query-service/main.go b/cmd/query-service/main.go
index ed3a60b..2061f01 100755
--- a/cmd/query-service/main.go
+++ b/cmd/query-service/main.go
@@ -6,12 +6,14 @@ This program has been developed by students from the bachelor Computer Science a
 package main
 
 import (
+	"encoding/json"
 	"net/http"
 	"os"
 	"query-service/internal/usecases/consume"
 	"query-service/internal/usecases/produce"
 
 	"git.science.uu.nl/graphpolaris/go-common/microservice"
+	"git.science.uu.nl/graphpolaris/go-common/structs/v1/models"
 	"git.science.uu.nl/graphpolaris/query-conversion"
 	"git.science.uu.nl/graphpolaris/query-conversion/cypherv2"
 	queryexecution "git.science.uu.nl/graphpolaris/query-execution"
@@ -65,10 +67,50 @@ func main() {
 
 	go consumeService.Start()
 
+	http.HandleFunc("/execute-cypher-query", handleExecuteCypherQuery(queryExecutor))
+
 	// Expose /metrics endpoint for prometheus
 	log.Info().Int("port", 8080).Msg("starting prometheus metrics server")
 	http.Handle("/metrics", promhttp.Handler())
+
 	http.ListenAndServe(":8080", nil)
 
 	select {}
 }
+
+func handleExecuteCypherQuery(queryExecutor queryexecution.Executor) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		log.Info().Msg("Received request to execute Cypher query")
+		if r.Method == http.MethodPost {
+			var req struct {
+				Query string `json:"query"`
+			}
+			if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
+				log.Error().Err(err).Msg("Failed to decode request payload")
+				http.Error(w, "Invalid request payload", http.StatusBadRequest)
+				return
+			}
+
+			log.Info().Str("query", req.Query).Msg("Executing query")
+			result, err := queryExecutor.ExecuteQuery(req.Query, &models.DBConnectionModel{
+				URL:                  "demo.neo4jlabs.com",
+				Protocol:             "neo4j+s://",
+				Port:                 7687,
+				Username:             "movies",
+				Password:             "fire$10", //not sure what the password was
+				InternalDatabaseName: "movies",
+				Type:                 models.Neo4j,
+			})
+			if err != nil {
+				log.Error().Err(err).Msg("Query execution failed")
+				http.Error(w, err.Error(), http.StatusInternalServerError)
+				return
+			}
+			w.Header().Set("Content-Type", "application/json")
+			w.Write(*result)
+		} else {
+			log.Error().Msg("Invalid request method")
+			http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
+		}
+	}
+}
-- 
GitLab