29 lines
763 B
Go
29 lines
763 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type User struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Email string `gorm:"uniqueIndex;not null;size:255" json:"email"`
|
|
PasswordHash string `gorm:"not null" json:"-"`
|
|
Name string `gorm:"not null" json:"name"`
|
|
Role string `gorm:"not null;default:user" json:"role"` // "admin" or "user"
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
Assignments []Assignment `gorm:"foreignKey:UserID" json:"assignments,omitempty"`
|
|
}
|
|
|
|
func (u *User) IsAdmin() bool {
|
|
return u.Role == "admin"
|
|
}
|
|
|
|
func (u *User) GetID() uint {
|
|
return u.ID
|
|
}
|