From d85d37eb2d5091925b44dca28f1b6d43267700f4 Mon Sep 17 00:00:00 2001 From: Vargha Csongor Date: Thu, 18 Apr 2024 22:35:48 +0200 Subject: [PATCH] Change responses --- backend/handlers/createPerson.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/handlers/createPerson.go b/backend/handlers/createPerson.go index 8b7177c..a6cb139 100644 --- a/backend/handlers/createPerson.go +++ b/backend/handlers/createPerson.go @@ -6,7 +6,6 @@ import ( "net/http" "github.com/gin-gonic/gin" - "github.com/google/uuid" "github.com/neo4j/neo4j-go-driver/v5/neo4j" "github.com/vcscsvcscs/GenerationsHeritage/backend/memgraph" ) @@ -23,24 +22,23 @@ func CreatePerson(driver neo4j.DriverWithContext) gin.HandlerFunc { var person memgraph.Person err := json.NewDecoder(c.Request.Body).Decode(&person) if err != nil { - log.Printf("ip: %s error: %s", c.ClientIP(), err) + log.Printf("ip: %s error: %s", c.ClientIP(), err.Error()) c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"}) return } - person.ID = uuid.New().String() - if person.Verify() != nil { - log.Printf("ip: %s error: %s", c.ClientIP(), err) - c.JSON(http.StatusBadRequest, gin.H{"error": "invalid person information"}) + if err := person.Verify(); err != nil { + log.Printf("ip: %s error: %s", c.ClientIP(), err.Error()) + c.JSON(http.StatusBadRequest, gin.H{"error": "contains-forbidden-characters"}) return } rec, err := person.CreatePerson(driver) if err != nil { - log.Printf("ip: %s error: %s", c.ClientIP(), err) - c.JSON(http.StatusNotFound, gin.H{"error": "could not create person with information provided"}) + log.Printf("ip: %s error: %s", c.ClientIP(), err.Error()) + c.JSON(http.StatusBadRequest, gin.H{"error": "already-exists"}) return }