Updated User model fields

This commit is contained in:
strNophix 2022-09-28 16:14:30 +02:00
parent 4f8d553923
commit db1bee79ac
4 changed files with 4 additions and 5 deletions

@ -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),
})

@ -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")

@ -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

@ -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