admin

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTransition      = fmt.Errorf("invalid status transition")
	ErrConcurrentModification = fmt.Errorf("user status was modified by another request")
	ErrInvalidAccountStatus   = fmt.Errorf("invalid account status value")
)

Functions

This section is empty.

Types

type AdminUserResponse

type AdminUserResponse struct {
	ID             string             `json:"id"`
	Email          string             `json:"email"`
	IsAdmin        bool               `json:"is_admin"`
	AccountStatus  core.AccountStatus `json:"account_status"`
	SignupReason   *string            `json:"signup_reason,omitempty"`
	TrialStartedAt *time.Time         `json:"trial_started_at,omitempty"`
	CreatedAt      time.Time          `json:"created_at"`
	UpdatedAt      time.Time          `json:"updated_at"`
}

func ToAdminUserResponse

func ToAdminUserResponse(u *User) AdminUserResponse

type AdminUsersListResponse

type AdminUsersListResponse struct {
	Data []AdminUserResponse `json:"data"`
}

type DBUser

type DBUser struct {
	ID             string             `db:"id"`
	Email          string             `db:"email"`
	IsAdmin        bool               `db:"is_admin"`
	AccountStatus  core.AccountStatus `db:"account_status"`
	SignupReason   *string            `db:"signup_reason"`
	TrialStartedAt *int64             `db:"trial_started_at"`
	CreatedAt      int64              `db:"created_at"`
	UpdatedAt      int64              `db:"updated_at"`
}

DBUser represents a user record from the database.

type Handler

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

func NewHandler

func NewHandler(adminSvc *Service, logger *slog.Logger) *Handler

func (*Handler) ListUsers

func (h *Handler) ListUsers(w http.ResponseWriter, r *http.Request)

func (*Handler) UpdateUserStatus

func (h *Handler) UpdateUserStatus(w http.ResponseWriter, r *http.Request)

type Mailer

type Mailer interface {
	SendAccountApproved(ctx context.Context, to string) error
	SendAccountBlocked(ctx context.Context, to string) error
	SendAccountReactivated(ctx context.Context, to string) error
}

type Repository

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

Repository provides data access for the admin domain.

func NewRepository

func NewRepository(db *sqlx.DB) *Repository

NewRepository creates a new admin repository.

func (*Repository) GetAllUsers

func (r *Repository) GetAllUsers(ctx context.Context) ([]DBUser, error)

GetAllUsers retrieves all users ordered by creation date.

func (*Repository) GetUserByID

func (r *Repository) GetUserByID(ctx context.Context, userID string) (*DBUser, error)

GetUserByID retrieves a user by ID.

func (*Repository) UpdateAccountStatus

func (r *Repository) UpdateAccountStatus(ctx context.Context, userID string, fromStatus core.AccountStatus, toStatus core.AccountStatus) (bool, error)

UpdateAccountStatus updates a user's account_status with optimistic locking. Returns (true, nil) if RowsAffected == 1, (false, nil) if RowsAffected == 0.

type Service

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

Service provides admin business logic.

func NewService

func NewService(repo *Repository, sessionRevoker SessionRevoker, mailer Mailer, logger *slog.Logger) *Service

NewService creates a new admin service.

func (*Service) ListUsers

func (s *Service) ListUsers(ctx context.Context) ([]User, error)

ListUsers retrieves all users.

func (*Service) UpdateUserStatus

func (s *Service) UpdateUserStatus(ctx context.Context, userID string, targetStatus core.AccountStatus, adminID string) (*User, error)

UpdateUserStatus updates a user's account status.

type SessionRevoker

type SessionRevoker interface {
	RevokeAllSessions(ctx context.Context, userID string) error
}

type UpdateUserStatusRequest

type UpdateUserStatusRequest struct {
	AccountStatus core.AccountStatus `json:"account_status"`
}

type User

type User struct {
	ID             string
	Email          string
	IsAdmin        bool
	AccountStatus  core.AccountStatus
	SignupReason   *string
	TrialStartedAt *time.Time
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

User represents a user in the admin domain.

Jump to

Keyboard shortcuts

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