Skip to content
Snippets Groups Projects
Commit 082d9e2b authored by Samed's avatar Samed
Browse files

Test commit

parent 8dc974b2
No related tags found
No related merge requests found
Pipeline #138004 passed
......@@ -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)
}
}
}
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