switch db schema to snake case for better frontend/backend/db integration

This commit is contained in:
2024-05-05 16:13:22 +02:00
parent a7ad330b27
commit b2ef584057
11 changed files with 51 additions and 41 deletions

View File

@@ -15,6 +15,7 @@ require (
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/cors v1.7.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect

View File

@@ -14,6 +14,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/cors v1.7.1 h1:s9SIppU/rk8enVvkzwiC2VK3UZ/0NNGsWfUKvV55rqs=
github.com/gin-contrib/cors v1.7.1/go.mod h1:n/Zj7B4xyrgk/cX1WCX2dkzFfaNm/xJb6oIUk7WTtps=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
@@ -93,6 +95,7 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -9,6 +9,7 @@ import (
"syscall"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/vcscsvcscs/GenerationsHeritage/backend/handlers"
"github.com/vcscsvcscs/GenerationsHeritage/backend/memgraph"
@@ -43,6 +44,11 @@ func main() {
memgraphDriver := memgraph.InitDatabase(*memgraphURI, *memgraphUser, *memgraphPass)
router := gin.Default()
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:5173", "http://localhost"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
router.GET("/health", hc.HealthCheckHandler())
router.GET("/person", handlers.ViewPerson(memgraphDriver))
router.POST("/person", handlers.CreatePerson(memgraphDriver))

View File

@@ -19,7 +19,7 @@ func (r *Relationship) CreateRelationship(driver neo4j.DriverWithContext) (*neo4
return nil, err
}
query := fmt.Sprintf(`MATCH (a:Person), (b:Person) WHERE a.ID = '%s' AND b.ID = '%s'`, r.FirstPersonID, r.SecondPersonID)
query := fmt.Sprintf(`MATCH (a:Person), (b:Person) WHERE a.id = '%s' AND b.id = '%s'`, r.FirstPersonID, r.SecondPersonID)
if r.Direction == "->" {
query = fmt.Sprintf(`%s CREATE (a)-[r:%s {verified: false}]->(b) RETURN r;`, query, r.Relationship)

View File

@@ -23,7 +23,7 @@ func (rp *RelationshipAndPerson) CreateRelationshipAndPerson(driver neo4j.Driver
rp.Person.ID = strings.ReplaceAll(uuid.New().String(), "-", "")
query := fmt.Sprintf(`MATCH (a:Person) WHERE a.ID = '%s'`, rp.Relationship.FirstPersonID)
query := fmt.Sprintf(`MATCH (a:Person) WHERE a.id = '%s'`, rp.Relationship.FirstPersonID)
query = fmt.Sprintf("%s CREATE (b:Person {%s})", query, rp.Person.ToString())

View File

@@ -17,12 +17,12 @@ func createIndexes(driver neo4j.DriverWithContext) error {
defer session.Close(ctx)
indexes := []string{
`CREATE INDEX ON :Person(ID);`,
`CREATE INDEX ON :Person(Lastname);`,
`CREATE INDEX ON :Person(Firstname);`,
`CREATE INDEX ON :Person(Born);`,
`CREATE INDEX ON :Person(MothersFirstname);`,
`CREATE INDEX ON :Person(MothersLastname);`,
`CREATE INDEX ON :Person(id);`,
`CREATE INDEX ON :Person(last_name);`,
`CREATE INDEX ON :Person(first_name);`,
`CREATE INDEX ON :Person(born);`,
`CREATE INDEX ON :Person(mothers_firstname);`,
`CREATE INDEX ON :Person(mothers_last_name);`,
}
// Run index queries via implicit auto-commit transaction
@@ -44,14 +44,14 @@ func createConstraints(driver neo4j.DriverWithContext) error {
defer session.Close(ctx)
constraints := []string{
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.ID);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.Lastname);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.Firstname);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.Born);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.MothersFirstname);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.MothersLastname);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT n.ID IS UNIQUE;`,
`CREATE CONSTRAINT ON (n:Person) ASSERT n.Lastname, n.Firstname, n.Born, n.MothersFirstname, n.MothersLastname IS UNIQUE;`,
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.id);`,
`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_firstname);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT EXISTS (n.mothers_lastname);`,
`CREATE CONSTRAINT ON (n:Person) ASSERT n.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;`,
}
// Run index queries via implicit auto-commit transaction

View File

@@ -19,7 +19,7 @@ func (p *Person) DeletePerson(driver neo4j.DriverWithContext) error {
return err
}
query := fmt.Sprintf("MATCH (n:Person {ID: '%s'}) DELETE n;", p.ID)
query := fmt.Sprintf("MATCH (n:Person {id: '%s'}) DELETE n;", p.ID)
_, err := session.Run(ctx, query, nil)

View File

@@ -28,7 +28,7 @@ func (r *Relationship) DeleteRelationship(driver neo4j.DriverWithContext) error
query = fmt.Sprintf(`MATCH (a)-[r:%s]-(b)`, r.Relationship)
}
query = fmt.Sprintf(`%s WHERE a.ID = '%s' AND b.ID = '%s' DELETE r;`, query, r.FirstPersonID, r.SecondPersonID)
query = fmt.Sprintf(`%s WHERE a.id = '%s' AND b.id = '%s' DELETE r;`, query, r.FirstPersonID, r.SecondPersonID)
_, err := session.Run(ctx, query, nil)

View File

@@ -38,46 +38,46 @@ type Person struct {
}
func (p *Person) ToString() string {
result := fmt.Sprintf("ID: '%s'", p.ID)
result := fmt.Sprintf("id: '%s'", p.ID)
if p.Firstname != "" {
result = fmt.Sprintf("%s, Firstname: '%s'", result, p.Firstname)
result = fmt.Sprintf("%s, first_name: '%s'", result, p.Firstname)
}
if p.Lastname != "" {
result = fmt.Sprintf("%s, Lastname: '%s'", result, p.Lastname)
result = fmt.Sprintf("%s, last_name: '%s'", result, p.Lastname)
}
if p.Middlename != "" {
result = fmt.Sprintf("%s, Middlename: '%s'", result, p.Middlename)
result = fmt.Sprintf("%s, middle_name: '%s'", result, p.Middlename)
}
if p.MothersFirstname != "" {
result = fmt.Sprintf("%s, MothersFirstname: '%s'", result, p.MothersFirstname)
result = fmt.Sprintf("%s, mothers_first_name: '%s'", result, p.MothersFirstname)
}
if p.MothersLastname != "" {
result = fmt.Sprintf("%s, MothersLastname: '%s'", result, p.MothersLastname)
result = fmt.Sprintf("%s, mothers_last_name: '%s'", result, p.MothersLastname)
}
if !p.Born.IsZero() {
result = fmt.Sprintf("%s, Born: date({year:%d, month:%d, day:%d})", result, p.Born.Year(), p.Born.Month(), p.Born.Day())
result = fmt.Sprintf("%s, born: date({year:%d, month:%d, day:%d})", result, p.Born.Year(), p.Born.Month(), p.Born.Day())
}
if !p.Death.IsZero() {
result = fmt.Sprintf("%s, Death: date({year:%d, month:%d, day:%d})", result, p.Death.Year(), p.Death.Month(), p.Death.Day())
result = fmt.Sprintf("%s, death: date({year:%d, month:%d, day:%d})", result, p.Death.Year(), p.Death.Month(), p.Death.Day())
}
if p.Birthplace != "" {
result = fmt.Sprintf("%s, Birthplace: '%s'", result, p.Birthplace)
result = fmt.Sprintf("%s, birthplace: '%s'", result, p.Birthplace)
}
if p.Residence != "" {
result = fmt.Sprintf("%s, Residence: '%s'", result, p.Residence)
result = fmt.Sprintf("%s, residence: '%s'", result, p.Residence)
}
if p.Deathplace != "" {
result = fmt.Sprintf("%s, Deathplace: '%s'", result, p.Deathplace)
result = fmt.Sprintf("%s, deathplace: '%s'", result, p.Deathplace)
}
if p.OccupationToDisplay != "" {
result = fmt.Sprintf("%s, OccupationToDisplay: '%s'", result, p.OccupationToDisplay)
result = fmt.Sprintf("%s, occupation_to_display: '%s'", result, p.OccupationToDisplay)
}
if p.ProfilePicture != "" {
result = fmt.Sprintf("%s, ProfilePicture: '%s'", result, p.ProfilePicture)
result = fmt.Sprintf("%s, profile_picture: '%s'", result, p.ProfilePicture)
}
if p.Titles != nil && len(p.Titles) > 0 {
result = fmt.Sprintf("%s, Titles: [", result)
result = fmt.Sprintf("%s, titles: [", result)
for _, title := range p.Titles {
result = fmt.Sprintf("%s'%s', ", result, title)
}
@@ -85,7 +85,7 @@ func (p *Person) ToString() string {
}
if p.Suffixes != nil && len(p.Suffixes) > 0 {
result = fmt.Sprintf("%s, Suffixes: [", result)
result = fmt.Sprintf("%s, suffixes: [", result)
for _, suffix := range p.Suffixes {
result = fmt.Sprintf("%s'%s', ", result, suffix)
}
@@ -93,7 +93,7 @@ func (p *Person) ToString() string {
}
if p.ExtraNames != nil && len(p.ExtraNames) > 0 {
result = fmt.Sprintf("%s, ExtraNames: [", result)
result = fmt.Sprintf("%s, extra_names: [", result)
for _, extraName := range p.ExtraNames {
result = fmt.Sprintf("%s'%s', ", result, extraName)
}
@@ -101,7 +101,7 @@ func (p *Person) ToString() string {
}
if p.Aliases != nil && len(p.Aliases) > 0 {
result = fmt.Sprintf("%s, Aliases: [", result)
result = fmt.Sprintf("%s, aliases: [", result)
for _, alias := range p.Aliases {
result = fmt.Sprintf("%s'%s', ", result, alias)
}
@@ -109,7 +109,7 @@ func (p *Person) ToString() string {
}
if p.LifeEvents != nil && len(p.LifeEvents) > 0 {
result = fmt.Sprintf("%s, LifeEvents: [", result)
result = fmt.Sprintf("%s, life_events: [", result)
for i := 0; i < len(p.LifeEvents); i++ {
date, dok := p.LifeEvents[i]["date"]
event, eok := p.LifeEvents[i]["event"]
@@ -121,7 +121,7 @@ func (p *Person) ToString() string {
}
if p.Occupations != nil && len(p.Occupations) > 0 {
result = fmt.Sprintf("%s, Occupations: [", result)
result = fmt.Sprintf("%s, occupations: [", result)
for _, occupation := range p.Occupations {
result = fmt.Sprintf("%s'%s', ", result, occupation)
@@ -131,7 +131,7 @@ func (p *Person) ToString() string {
}
if p.OthersSaid != nil {
result = fmt.Sprintf("%s, OthersSaid: {", result)
result = fmt.Sprintf("%s, others_said: {", result)
for key, value := range p.OthersSaid {
result = fmt.Sprintf("%s%s: '%s', ", result, key, value)
}
@@ -139,7 +139,7 @@ func (p *Person) ToString() string {
}
if p.Photos != nil && len(p.Photos) > 0 {
result = fmt.Sprintf("%s, Photos: {", result)
result = fmt.Sprintf("%s, photos: {", result)
for key, value := range p.Photos {
result = fmt.Sprintf("%s%s: '%s', ", result, key, value)
}

View File

@@ -19,7 +19,7 @@ func (p *Person) UpdatePerson(driver neo4j.DriverWithContext) (*neo4j.Record, er
return nil, err
}
query := fmt.Sprintf("MATCH (n:Person {ID: '%s'}) SET n += {%s} RETURN n;", p.ID, p.ToString())
query := fmt.Sprintf("MATCH (n:Person {id: '%s'}) SET n += {%s} RETURN n;", p.ID, p.ToString())
result, err := session.Run(ctx, query, nil)
if err != nil {

View File

@@ -28,7 +28,7 @@ func (r *Relationship) VerifyRelationship(driver neo4j.DriverWithContext) (*neo4
query = fmt.Sprintf(`MATCH (a)-[r:%s]-(b)`, r.Relationship)
}
query = fmt.Sprintf(`%s WHERE a.ID = %s AND b.ID = %s set r.verified = true return r;`, query, r.FirstPersonID, r.SecondPersonID)
query = fmt.Sprintf(`%s WHERE a.id = %s AND b.id = %s set r.verified = true return r;`, query, r.FirstPersonID, r.SecondPersonID)
result, err := session.Run(ctx, query, nil)
if err != nil {