Documentation
¶
Overview ¶
Package users contains the MVP user-management module.
The module covers:
- registration with email/password,
- login validation with account status checks,
- admin user listing and status management,
- password change endpoint.
Index ¶
- Constants
- Variables
- func IsValidRole(r Role) bool
- func IsValidStatus(s Status) bool
- func Module() fx.Option
- type Pagination
- type Repository
- func (r *Repository) Create(ctx context.Context, input UserInput, passwordHash string) (*User, error)
- func (r *Repository) GetByEmail(ctx context.Context, email string) (*UserWithPasswordHash, error)
- func (r *Repository) GetByID(ctx context.Context, id int64) (*UserWithPasswordHash, error)
- func (r *Repository) GetByIDs(ctx context.Context, ids []int64) (map[int64]User, error)
- func (r *Repository) IsAdminByID(ctx context.Context, id int64) (bool, error)
- func (r *Repository) List(ctx context.Context, status *Status, role *Role, pagination *Pagination) ([]User, int, error)
- func (r *Repository) Search(ctx context.Context, q string, pagination *Pagination) ([]User, int, error)
- func (r *Repository) Update(ctx context.Context, id int64, update UserUpdate) error
- func (r *Repository) UpdatePasswordHash(ctx context.Context, id int64, passwordHash string) error
- type Role
- type Service
- func (s *Service) ChangePassword(ctx context.Context, id int64, oldPassword, newPassword string) error
- func (s *Service) GetByID(ctx context.Context, id int64) (*User, error)
- func (s *Service) IsAdmin(ctx context.Context, id int64) (bool, error)
- func (s *Service) List(ctx context.Context, status *Status, role *Role, pagination *Pagination) ([]User, int, error)
- func (s *Service) Login(ctx context.Context, email, password string) (*User, error)
- func (s *Service) LookupByIDs(ctx context.Context, ids []int64) (map[int64]User, error)
- func (s *Service) Register(ctx context.Context, input UserInput) (*User, error)
- func (s *Service) Search(ctx context.Context, q string, pagination *Pagination) ([]User, int, error)
- func (s *Service) Update(ctx context.Context, id int64, update UserUpdate) error
- type Status
- type User
- type UserInput
- type UserUpdate
- type UserWithPasswordHash
Constants ¶
View Source
const ( DefaultLimit = 20 MaxLimit = 100 )
Variables ¶
Functions ¶
func IsValidRole ¶
IsValidRole checks if the role is one of the allowed values.
func IsValidStatus ¶
IsValidStatus checks if the status is one of the allowed values.
Types ¶
type Pagination ¶
type Pagination = db.Pagination[*pagination]
func NewPagination ¶
func NewPagination(limit, offset int) *Pagination
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(db *bun.DB) *Repository
func (*Repository) GetByEmail ¶
func (r *Repository) GetByEmail(ctx context.Context, email string) (*UserWithPasswordHash, error)
func (*Repository) GetByID ¶
func (r *Repository) GetByID(ctx context.Context, id int64) (*UserWithPasswordHash, error)
func (*Repository) GetByIDs ¶
GetByIDs retrieves multiple users by their IDs in a single query. Returns a map of user ID to User. Users that are not found are omitted from the map.
func (*Repository) IsAdminByID ¶
func (*Repository) List ¶
func (r *Repository) List( ctx context.Context, status *Status, role *Role, pagination *Pagination, ) ([]User, int, error)
func (*Repository) Search ¶
func (r *Repository) Search( ctx context.Context, q string, pagination *Pagination, ) ([]User, int, error)
func (*Repository) Update ¶
func (r *Repository) Update(ctx context.Context, id int64, update UserUpdate) error
func (*Repository) UpdatePasswordHash ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo *Repository) *Service
func (*Service) ChangePassword ¶
func (*Service) LookupByIDs ¶
LookupByIDs retrieves multiple users by their IDs in a single query. Returns a map of user ID to User. Users that are not found are omitted from the map.
type User ¶
type User struct {
ID int64
Email string
Name string
Role Role
Status Status
CreatedAt time.Time
UpdatedAt time.Time
}
User is the domain entity used by service and handler layers.
type UserUpdate ¶
func (UserUpdate) IsEmpty ¶
func (u UserUpdate) IsEmpty() bool
type UserWithPasswordHash ¶
Click to show internal directories.
Click to hide internal directories.