mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package domain
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type UserRole string
|
|
|
|
const (
|
|
UserRoleAdmin UserRole = "admin"
|
|
UserRoleUser UserRole = "user"
|
|
UserRoleContentManager UserRole = "content_manager"
|
|
UserRoleViewer UserRole = "viewer"
|
|
)
|
|
|
|
type User struct {
|
|
ID string `gorm:"primaryKey;type:text"`
|
|
Email string `gorm:"uniqueIndex;not null;type:text"`
|
|
Name string `gorm:"type:text"` // Primary name (Russian)
|
|
Password string `gorm:"not null;type:text"`
|
|
Role UserRole `gorm:"type:varchar(50);default:'user'"`
|
|
Permissions string `gorm:"type:jsonb;default:'[]'"` // JSON array of permissions
|
|
LastLoginAt *time.Time `gorm:"index"`
|
|
IsActive bool `gorm:"default:true;index"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
|
}
|
|
|
|
// TableName specifies the table name for GORM
|
|
func (User) TableName() string {
|
|
return "users"
|
|
}
|
|
|
|
type UserListFilters struct {
|
|
Role *UserRole
|
|
IsActive *bool
|
|
Search string // Search in email and name
|
|
}
|
|
|
|
type PaginationParams struct {
|
|
Limit int
|
|
Offset int
|
|
}
|
|
|
|
type PaginatedResult[T any] struct {
|
|
Items []T
|
|
Total int64
|
|
}
|
|
|
|
type UserRepository interface {
|
|
GetByEmail(ctx context.Context, email string) (*User, error)
|
|
GetByID(ctx context.Context, id string) (*User, error)
|
|
Create(ctx context.Context, user *User) error
|
|
Update(ctx context.Context, user *User) error // From BaseRepository
|
|
Delete(ctx context.Context, id string) error // From BaseRepository
|
|
List(ctx context.Context, filters UserListFilters, pagination PaginationParams) (*PaginatedResult[User], error)
|
|
UpdateRole(ctx context.Context, userID string, role UserRole) error
|
|
UpdatePermissions(ctx context.Context, userID string, permissions []string) error
|
|
Deactivate(ctx context.Context, userID string) error
|
|
Activate(ctx context.Context, userID string) error
|
|
UpdateLastLogin(ctx context.Context, userID string) error
|
|
}
|