nquest/pkg/models/user.go

37 lines
714 B
Go
Raw Normal View History

2023-11-01 23:21:12 +03:00
package models
import (
"errors"
2024-01-28 22:19:41 +03:00
"time"
"github.com/google/uuid"
"gorm.io/gorm"
2023-11-01 23:21:12 +03:00
)
2024-01-05 03:50:33 +03:00
var ErrEmptyPassword = errors.New("empty password")
2023-11-01 23:21:12 +03:00
type User struct {
2024-01-28 22:19:41 +03:00
ID uuid.UUID `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Username string `gorm:"unique" json:"username"`
Email string `gorm:"unique" json:"email"`
Password string `json:"-"`
2024-01-05 03:50:33 +03:00
Experience int
Games []*GameCursor
2024-01-21 02:20:59 +03:00
Role UserRole
2023-11-01 23:21:12 +03:00
}
2024-01-21 02:20:59 +03:00
func (u *User) HasRole(role UserRole) bool {
return u.Role >= role
}
type UserRole int
const (
RoleUser UserRole = iota
RoleCreator
RoleAdmin
)