mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 23:09:07 +02:00
init api implementations
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
type HealthCheck interface {
|
||||
SetStatus(status string)
|
||||
GetStatus() string
|
||||
HealthCheckHandler() gin.HandlerFunc
|
||||
HealthCheckHandler(c *gin.Context)
|
||||
}
|
||||
|
||||
type healthCheck struct {
|
||||
@@ -38,17 +38,15 @@ func (hc *healthCheck) GetStatus() string {
|
||||
return hc.status
|
||||
}
|
||||
|
||||
func (hc *healthCheck) HealthCheckHandler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
switch hc.GetStatus() {
|
||||
case "nok":
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"status": hc.GetStatus(),
|
||||
})
|
||||
default:
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": hc.GetStatus(),
|
||||
})
|
||||
}
|
||||
func (hc *healthCheck) HealthCheckHandler(c *gin.Context) {
|
||||
switch hc.GetStatus() {
|
||||
case "nok":
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{
|
||||
"msg": hc.GetStatus(),
|
||||
})
|
||||
default:
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"msg": hc.GetStatus(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -83,9 +83,11 @@ func TestHealthCheck_SetStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHealthCheck_HealthCheckHandler(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := gin.Default()
|
||||
hc := New()
|
||||
r.GET("/health", hc.HealthCheckHandler())
|
||||
r.GET("/health", hc.HealthCheckHandler)
|
||||
type args struct {
|
||||
status string
|
||||
}
|
||||
@@ -100,7 +102,7 @@ func TestHealthCheck_HealthCheckHandler(t *testing.T) {
|
||||
args: args{
|
||||
status: "ok",
|
||||
},
|
||||
want: `{"status":"ok"}`,
|
||||
want: `{"msg":"ok"}`,
|
||||
statusCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
@@ -108,12 +110,13 @@ func TestHealthCheck_HealthCheckHandler(t *testing.T) {
|
||||
args: args{
|
||||
status: "nok",
|
||||
},
|
||||
want: `{"status":"nok"}`,
|
||||
statusCode: http.StatusInternalServerError,
|
||||
want: `{"msg":"nok"}`,
|
||||
statusCode: http.StatusServiceUnavailable,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hc.SetStatus(tt.args.status)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
@@ -0,0 +1,4 @@
|
||||
MATCH (a:Person), (b:Person)
|
||||
WHERE id(a) = $id1 AND id(b) = $id2
|
||||
CREATE (a)-[r:Relationship $Relationship]->(b)
|
||||
RETURN r AS relationship
|
@@ -0,0 +1 @@
|
||||
CREATE (p:Person $Person) RETURN p as person
|
@@ -0,0 +1,4 @@
|
||||
MATCH (a:Person), (b:Person)
|
||||
WHERE id(a) = $id1 AND id(b) = $id2
|
||||
CREATE (a)-[r:Relationship $Relationship]-(b)
|
||||
RETURN r as relationship
|
@@ -0,0 +1,5 @@
|
||||
MATCH (a:Person), (b:Person)
|
||||
WHERE id(a) = $id1 AND id(b) = $id2
|
||||
CREATE (a)-[r1:Relationship $Relationship1]->(b)
|
||||
CREATE (b)-[r2:Relationship $Relationship2]->(a)
|
||||
RETURN r1 as relationship1, r2 as relationship2
|
@@ -0,0 +1,8 @@
|
||||
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
|
||||
WHERE id(n) = $id
|
||||
OPTIONAL MATCH (family)-[c:Child]->(children:Person)
|
||||
WITH family, p, children, c, n
|
||||
OPTIONAL MATCH (children)<-[p2:Parent]-(OtherParents:Person)
|
||||
WITH family, p, children, c, OtherParents, p2, n
|
||||
OPTIONAL MATCH (family)-[s:Spouse]-(spouse:Person)
|
||||
RETURN family, p, children, c, OtherParents, p2, spouse, s, n;
|
@@ -0,0 +1 @@
|
||||
MATCH (n:Person) WHERE n.id = $id RETURN n AS people
|
@@ -0,0 +1 @@
|
||||
MATCH (n:Person) WHERE n.google_id = $google_id RETURN n as person
|
@@ -0,0 +1 @@
|
||||
MATCH (n:Person) WHERE id(n) = $id RETURN n as person
|
@@ -0,0 +1,3 @@
|
||||
MATCH (n)-[r]-(o)
|
||||
WHERE id(n) = $id1 AND id(o) = $id2
|
||||
RETURN r as relationship
|
@@ -0,0 +1,3 @@
|
||||
MATCH (n:DeletedPerson)
|
||||
WHERE id(n) = $id
|
||||
DETACH DELETE n;
|
14
apps/db-handler/pkg/memgraph/queries/schema.cypher
Normal file
14
apps/db-handler/pkg/memgraph/queries/schema.cypher
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.last_name);
|
||||
CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.first_name);
|
||||
CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.born);
|
||||
CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.mothers_first_name);
|
||||
CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.mothers_last_name);
|
||||
CREATE CONSTRAINT ON (n:Person) ASSERT n.google_id IS UNIQUE;
|
||||
CREATE CONSTRAINT ON (n:Person) ASSERT n.last_name, n.first_name, n.born, n.mothers_first_name, n.mothers_last_name IS UNIQUE;
|
||||
|
||||
CREATE INDEX ON :Person(google_id);
|
||||
CREATE INDEX ON :Person(last_name);
|
||||
CREATE INDEX ON :Person(first_name);
|
||||
CREATE INDEX ON :Person(born);
|
||||
CREATE INDEX ON :Person(mothers_first_name);
|
||||
CREATE INDEX ON :Person(mothers_last_name);
|
@@ -0,0 +1,4 @@
|
||||
MATCH (n:Person {id: $id})
|
||||
SET n:DeletedPerson
|
||||
REMOVE n:Person
|
||||
RETURN labels(n) AS labels, n AS person
|
@@ -0,0 +1,4 @@
|
||||
MATCH (n:Person)
|
||||
WHERE id(n) = $id
|
||||
SET n += $props
|
||||
RETURN n AS person
|
@@ -1,29 +0,0 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func SetupLogger(logToFileAndStd bool, logToFile bool) {
|
||||
if logToFileAndStd || logToFile {
|
||||
gin.DisableConsoleColor() // Disable Console Color, you don't need console color when writing the logs to file.
|
||||
path := fmt.Sprintf("private/logs/%02dy_%02dm_%02dd_%02dh_%02dm_%02ds.log", time.Now().Year(), time.Now().Month(), time.Now().Day(), time.Now().Hour(), time.Now().Minute(), time.Now().Second())
|
||||
logerror1 := os.MkdirAll("private/logs/", 0755)
|
||||
f, logerror2 := os.Create(path)
|
||||
if logerror1 != nil || logerror2 != nil {
|
||||
log.Println("Cant log to file")
|
||||
} else if logToFileAndStd {
|
||||
gin.DefaultWriter = io.MultiWriter(f, os.Stdout)
|
||||
} else {
|
||||
gin.DefaultWriter = io.MultiWriter(f)
|
||||
}
|
||||
}
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
log.SetOutput(gin.DefaultErrorWriter)
|
||||
}
|
Reference in New Issue
Block a user