users

package
v0.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateUserOptions

type CreateUserOptions struct {
	Username             string
	Email                *string
	Password             string
	RoleID               int
	LibraryIDs           []int
	AllLibraryAccess     bool
	RequirePasswordReset bool
}

CreateUserOptions contains options for creating a user.

type CreateUserPayload

type CreateUserPayload struct {
	Username             string  `json:"username" validate:"required,min=3,max=50"`
	Email                *string `json:"email" validate:"omitempty,email"`
	Password             string  `json:"password" validate:"required,min=8"`
	RoleID               int     `json:"role_id" validate:"required"`
	LibraryIDs           []int   `json:"library_ids"`        // Empty means no access, special value -1 means all libraries
	AllLibraryAccess     bool    `json:"all_library_access"` // If true, user has access to all libraries
	RequirePasswordReset bool    `json:"require_password_reset"`
}

CreateUserPayload represents the request body for creating a user.

type ListOptions

type ListOptions struct {
	Limit  int
	Offset int
}

ListOptions contains options for listing users.

type ListUsersQuery

type ListUsersQuery struct {
	Limit  int `query:"limit" default:"50"`
	Offset int `query:"offset" default:"0"`
}

ListUsersQuery represents the query parameters for listing users.

type ResetPasswordPayload

type ResetPasswordPayload struct {
	CurrentPassword      *string `json:"current_password"` // Required for normal self-reset (not forced-reset flow)
	NewPassword          string  `json:"new_password" validate:"required,min=8"`
	RequirePasswordReset bool    `json:"require_password_reset"`
}

ResetPasswordPayload represents the request body for resetting a password.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles user operations.

func NewService

func NewService(db *bun.DB) *Service

NewService creates a new users service.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, db *bun.DB, authMiddleware *auth.Middleware) *Service

RegisterRoutes registers all user routes.

func (*Service) CountUsers

func (s *Service) CountUsers(ctx context.Context) (int, error)

CountUsers returns the total number of users.

func (*Service) Create

func (s *Service) Create(ctx context.Context, opts CreateUserOptions) (*models.User, error)

Create creates a new user.

func (*Service) Deactivate

func (s *Service) Deactivate(ctx context.Context, userID int) error

Deactivate deactivates a user (soft delete).

func (*Service) List

func (s *Service) List(ctx context.Context, opts ListOptions) ([]*models.User, int, error)

List returns a paginated list of users.

func (*Service) ResetPassword

func (s *Service) ResetPassword(ctx context.Context, userID int, newPassword string, requirePasswordReset bool) error

ResetPassword changes a user's password.

func (*Service) Retrieve

func (s *Service) Retrieve(ctx context.Context, id int) (*models.User, error)

Retrieve gets a user by ID.

func (*Service) Update

func (s *Service) Update(ctx context.Context, user *models.User, opts UpdateOptions) error

Update updates a user.

func (*Service) VerifyPassword

func (s *Service) VerifyPassword(ctx context.Context, userID int, password string) (bool, error)

VerifyPassword checks if the password is correct for a user.

type UpdateOptions

type UpdateOptions struct {
	Columns             []string
	UpdateLibraryAccess bool
	AllLibraryAccess    bool
	LibraryIDs          []int
}

UpdateOptions contains options for updating a user.

type UpdateUserPayload

type UpdateUserPayload struct {
	Username         *string `json:"username" validate:"omitempty,min=3,max=50"`
	Email            *string `json:"email" validate:"omitempty,email"`
	RoleID           *int    `json:"role_id"`
	IsActive         *bool   `json:"is_active"`
	LibraryIDs       *[]int  `json:"library_ids"`        // If provided, replaces library access
	AllLibraryAccess *bool   `json:"all_library_access"` // If true, grants access to all libraries
}

UpdateUserPayload represents the request body for updating a user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL