start user model
This commit is contained in:
parent
d9d38c3df4
commit
7902f42c46
@ -21,6 +21,7 @@ func ConnectDatabase() {
|
|||||||
_ = db.AutoMigrate(&Author{})
|
_ = db.AutoMigrate(&Author{})
|
||||||
_ = db.AutoMigrate(&Format{})
|
_ = db.AutoMigrate(&Format{})
|
||||||
_ = db.AutoMigrate(&Order{})
|
_ = db.AutoMigrate(&Order{})
|
||||||
|
_ = db.AutoMigrate(&User{})
|
||||||
|
|
||||||
DB = db
|
DB = db
|
||||||
}
|
}
|
||||||
|
33
models/user.go
Normal file
33
models/user.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
ID uint `json:"id" gorm:"primary_key"`
|
||||||
|
Username string `json:"username" gorm:"unique"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateUserInput struct {
|
||||||
|
Username string `json:"username" binding:"required"`
|
||||||
|
Password string `json:"password" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateUserInput struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUser(id uint, username, password string, createdAt, updatedAt time.Time) User {
|
||||||
|
user := User{
|
||||||
|
ID: id,
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
CreatedAt: createdAt,
|
||||||
|
UpdatedAt: updatedAt,
|
||||||
|
}
|
||||||
|
return user
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user