gallery/api/models/user.go

38 lines
596 B
Go

package models
import (
"gorm.io/gorm"
)
type User struct {
gorm.Model
Username string `json:"username" gorm:"uniqueIndex, column: username"`
Password string
}
func (u User) Create() error {
return DB().Create(&u).Error
}
func (u *User) Read() error {
return Read(u)
}
func (u User) ReadAll(offset, limit int) ([]User, error) {
var users []User
err := ReadAll(&users, offset, limit)
return users, err
}
func (u *User) Update() error {
return Update(u, "username", u.Username)
}
func (u User) Delete() error {
err := u.Read()
if err == nil {
err = Delete(&u)
}
return err
}