domain

package
v0.0.0-...-1f1dc5f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package domain contains the administrator management business rules.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAdminID      = errors.New("invalid admin id")
	ErrInvalidUsername     = errors.New("invalid username")
	ErrInvalidDisplayName  = errors.New("invalid display name")
	ErrInvalidPasswordHash = errors.New("invalid password hash")
	ErrAdminNeedsRole      = errors.New("admin needs at least one role")
	ErrInvalidActiveRole   = errors.New("active role is not assigned")
)

Administrator validation errors.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	ID           int64
	Username     string
	DisplayName  string
	Email        string
	PasswordHash []byte
	RoleIDs      []int64
	ActiveRoleID int64
	Active       bool
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

Admin is a validated back-office user that can sign in and operate management APIs.

func NewAdmin

func NewAdmin(username, displayName, email string, passwordHash []byte, roleIDs []int64, activeRoleID int64) (Admin, error)

NewAdmin validates and creates an admin before it is persisted.

func RestoreAdmin

func RestoreAdmin(id int64, username, displayName, email string, passwordHash []byte, roleIDs []int64, activeRoleID int64, active bool, createdAt, updatedAt time.Time) (Admin, error)

RestoreAdmin rebuilds an admin from a trusted store representation.

func (Admin) HasRole

func (a Admin) HasRole(roleID int64) bool

HasRole reports whether the admin is assigned roleID.

func (Admin) ReplacePassword

func (a Admin) ReplacePassword(passwordHash []byte) (Admin, error)

ReplacePassword changes the admin password hash.

func (Admin) SwitchActiveRole

func (a Admin) SwitchActiveRole(roleID int64) (Admin, error)

SwitchActiveRole changes the role that authorization should use for new tokens.

func (Admin) UpdateProfile

func (a Admin) UpdateProfile(displayName, email string, roleIDs []int64, activeRoleID int64, active bool) (Admin, error)

UpdateProfile changes mutable admin fields while preserving identity and password.

Jump to

Keyboard shortcuts

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