Files
base/internal/domain/auth/user.go
2026-04-10 18:25:21 +03:30

66 lines
1.4 KiB
Go

package auth
import (
"time"
"github.com/google/uuid"
)
//go:generate stringer -type=UserStatus
type UserStatus int
const (
UserStatusActive UserStatus = iota
UserStatusInactive
UserStatusPending
UserStatusDeleted
)
// User represents a user aggregate root
// The repository handles loading of related entities (Roles, Accounts)
// This keeps the domain entity pure and decoupled from infrastructure
type User struct {
ID uuid.UUID
FirstName string
LastName string
PhoneNumber string
Email string
EmailVerified bool
Status UserStatus
InvitationCode string
Roles []Role
Accounts []Account
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
}
// HasRole checks if the user has a specific role
func (u *User) HasRole(roleName string) bool {
for _, role := range u.Roles {
if role.Name == roleName {
return true
}
}
return false
}
// GetRoleNames returns a slice of role names
func (u *User) GetRoleNames() []string {
names := make([]string, len(u.Roles))
for i, role := range u.Roles {
names[i] = role.Name
}
return names
}
// HasAccount checks if the user has an account for the given provider
func (u *User) HasAccount(provider string) bool {
for _, account := range u.Accounts {
if account.Provider.String() == provider {
return true
}
}
return false
}