diff --git a/models/models.go b/models/models.go index 06eaf43..b9df6c9 100644 --- a/models/models.go +++ b/models/models.go @@ -21,6 +21,7 @@ func ConnectDatabase() { _ = db.AutoMigrate(&Author{}) _ = db.AutoMigrate(&Format{}) _ = db.AutoMigrate(&Order{}) + _ = db.AutoMigrate(&User{}) DB = db } diff --git a/models/user.go b/models/user.go new file mode 100644 index 0000000..d2d1934 --- /dev/null +++ b/models/user.go @@ -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 +}