From db1bee79ac6e36ffaf122051eeb8621e82032d7a Mon Sep 17 00:00:00 2001 From: strNophix Date: Wed, 28 Sep 2022 16:14:30 +0200 Subject: [PATCH] Updated User model fields --- pkg/database/connection.go | 2 +- pkg/handler/userLogin.go | 2 +- pkg/handler/userRegister.go | 2 +- pkg/models/users.go | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/database/connection.go b/pkg/database/connection.go index 3e1df53..fd020b5 100644 --- a/pkg/database/connection.go +++ b/pkg/database/connection.go @@ -25,7 +25,7 @@ func ConnectDb() { log.Fatal("Failed to setup snowflake generator. \n", err) } - dsn := "host=postgres user=postgres password=postgres dbname=postgres port=5432 sslmode=disable" + dsn := "host=localhost user=postgres password=postgres dbname=postgres port=5432 sslmode=disable" db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{ Logger: logger.Default.LogMode(logger.Info), }) diff --git a/pkg/handler/userLogin.go b/pkg/handler/userLogin.go index cfdb2c2..6b36019 100644 --- a/pkg/handler/userLogin.go +++ b/pkg/handler/userLogin.go @@ -31,7 +31,7 @@ func Login(ctx *fiber.Ctx) error { } user := new(models.User) - result := db.Where(&models.User{Username: body.Username, Password: body.Password}).Select("id").First(user) + result := db.Where(&models.User{Login: body.Username, Password: body.Password}).Select("id").First(user) if result.Error != nil { return errors.New("invalid combination of username and password") diff --git a/pkg/handler/userRegister.go b/pkg/handler/userRegister.go index 3297094..61bd31e 100644 --- a/pkg/handler/userRegister.go +++ b/pkg/handler/userRegister.go @@ -30,7 +30,7 @@ func Register(ctx *fiber.Ctx) error { return err } - user := models.User{ID: database.GetID(), Username: body.Username, Password: body.Password, Email: body.Email} + user := models.User{ID: database.GetID(), Login: body.Username, Password: body.Password, Email: body.Email} result := db.Create(&user) if result.Error != nil { return result.Error diff --git a/pkg/models/users.go b/pkg/models/users.go index eb9a853..e96e563 100644 --- a/pkg/models/users.go +++ b/pkg/models/users.go @@ -6,10 +6,9 @@ import ( type User struct { ID int64 `json:"id,omitempty" gorm:"primaryKey"` - Username string `json:"name,omitempty" gorm:"unique"` + Login string `json:"name,omitempty" gorm:"unique"` Email string `json:"email"` Password string `json:"password,omitempty"` - Avatar string `json:"avatar,omitempty"` CreatedAt time.Time UpdatedAt time.Time