diff --git a/controllers/manufacturerController.go b/controllers/manufacturerController.go index cc0662b..bab3308 100644 --- a/controllers/manufacturerController.go +++ b/controllers/manufacturerController.go @@ -16,18 +16,14 @@ func CreateManufacturer(c *gin.Context, manufacturer database.Manufacturer) { validate := validators.Validate response := message.Response{Status: 200} - err := validate.Struct(manufacturer) - - if err != nil { + if err := validate.Struct(manufacturer); err != nil { response.Error = libs.GetValidationErrors(err.(validator.ValidationErrors)) response.Status = 400 message.SendResponse(c, response) return } - err = db.Create(&manufacturer).Error - - if err != nil { + if err := db.Create(&manufacturer).Error; err != nil { log.Println(err.Error()) response.Error = gin.H{ "error": err.Error(), diff --git a/controllers/userController.go b/controllers/userController.go new file mode 100644 index 0000000..2d32936 --- /dev/null +++ b/controllers/userController.go @@ -0,0 +1 @@ +package controllers diff --git a/database/models.go b/database/models.go index 0e94c6f..0ed8120 100644 --- a/database/models.go +++ b/database/models.go @@ -21,4 +21,5 @@ type User struct { Email string Password string Products []*Product `gorm:"many2many:user_products;"` + Token string `gorm:"many2many:user_token;"` } diff --git a/go.mod b/go.mod index 9f59428..5c02a9f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.22.3 require ( github.com/gin-gonic/gin v1.10.0 + github.com/go-playground/validator/v10 v10.20.0 gorm.io/driver/postgres v1.5.7 gorm.io/gorm v1.25.10 ) @@ -17,7 +18,6 @@ require ( 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 - github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect diff --git a/main.go b/main.go index da5da86..4672360 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,13 @@ func main() { controllers.EditManufacture(c, manufacturer) }) + r.POST("/registration", func(c *gin.Context) { + type registrationForm struct { + name string + email string + password string + } + }) err := r.Run() if err != nil { return