Merge remote-tracking branch 'origin/master'

This commit is contained in:
Владимир Шалимов 2024-06-06 14:37:34 +05:00
commit f9a63e7fce
5 changed files with 30 additions and 7 deletions

View File

@ -16,18 +16,14 @@ func CreateManufacturer(c *gin.Context, manufacturer database.Manufacturer) {
validate := validators.Validate validate := validators.Validate
response := message.Response{Status: 200} response := message.Response{Status: 200}
err := validate.Struct(manufacturer) if err := validate.Struct(manufacturer); err != nil {
if err != nil {
response.Error = libs.GetValidationErrors(err.(validator.ValidationErrors)) response.Error = libs.GetValidationErrors(err.(validator.ValidationErrors))
response.Status = 400 response.Status = 400
message.SendResponse(c, response) message.SendResponse(c, response)
return return
} }
err = db.Create(&manufacturer).Error if err := db.Create(&manufacturer).Error; err != nil {
if err != nil {
log.Println(err.Error()) log.Println(err.Error())
response.Error = gin.H{ response.Error = gin.H{
"error": err.Error(), "error": err.Error(),

View File

@ -0,0 +1,19 @@
package controllers
// Пример генератора токена
import (
"crypto/rand"
"fmt"
)
func tokenGenerator() string {
b := make([]byte, 4)
rand.Read(b)
return fmt.Sprintf("%x", b)
}
func main() {
a := tokenGenerator()
fmt.Println(a)
}

View File

@ -21,4 +21,5 @@ type User struct {
Email string Email string
Password string Password string
Products []*Product `gorm:"many2many:user_products;"` Products []*Product `gorm:"many2many:user_products;"`
Token string `gorm:"many2many:user_token;"`
} }

2
go.mod
View File

@ -4,6 +4,7 @@ go 1.22.3
require ( require (
github.com/gin-gonic/gin v1.10.0 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/driver/postgres v1.5.7
gorm.io/gorm v1.25.10 gorm.io/gorm v1.25.10
) )
@ -17,7 +18,6 @@ require (
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.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/goccy/go-json v0.10.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect

View File

@ -50,6 +50,13 @@ func main() {
controllers.EditManufacture(c, manufacturer) controllers.EditManufacture(c, manufacturer)
}) })
r.POST("/registration", func(c *gin.Context) {
type registrationForm struct {
name string
email string
password string
}
})
err := r.Run() err := r.Run()
if err != nil { if err != nil {
return return