usecase

package
v0.0.0-...-aca55d9 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package usecase contains business logic.

Package usecase contains business logic.

Package usecase contains business logic.

Package usecase provides business logic implementations.

Index

Constants

This section is empty.

Variables

ProviderSet provides all usecase layer dependencies.

Functions

This section is empty.

Types

type CreateDepartmentParams

type CreateDepartmentParams struct {
	Name        string
	Description string
	Enabled     bool
}

CreateDepartmentParams contains all parameters needed to create a department

type CreateRoleParams

type CreateRoleParams struct {
	Name        string
	Description string
	Enabled     bool
}

CreateRoleParams contains all parameters needed to create a role

type CreateUserParams

type CreateUserParams struct {
	Username     string
	Password     string
	FullName     string
	PhoneNumber  string
	Email        string
	Enabled      bool
	DepartmentID uint
	RoleID       uint
}

CreateUserParams contains all parameters needed to create a user

type Department

type Department struct {
	*model.Department
	UserCount int64
}

Department contains department data

type DepartmentRepository

type DepartmentRepository interface {
	Create(ctx context.Context, department *model.Department) error
	List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*model.Department, int, error)
	IsExists(ctx context.Context, filters map[string]any, notFilters map[string]any) (bool, error)
	Count(ctx context.Context, filters map[string]any, notFilters map[string]any) (int64, error)
	FindByID(ctx context.Context, id uint) (*model.Department, error)
	Update(ctx context.Context, department *model.Department, params map[string]any) error
	Delete(ctx context.Context, id uint) error
}

DepartmentRepository defines methods for department data access.

type DepartmentUseCase

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

DepartmentUseCase implements business logic for department operations.

func NewDepartmentUseCase

func NewDepartmentUseCase(tx Transaction, repo DepartmentRepository, userRepo UserRepository) *DepartmentUseCase

NewDepartmentUseCase creates a new instance of DepartmentUseCase.

func (*DepartmentUseCase) Create

Create creates a new department.

func (*DepartmentUseCase) Delete

func (uc *DepartmentUseCase) Delete(ctx context.Context, id uint) error

Delete removes a department.

func (*DepartmentUseCase) GetByID

func (uc *DepartmentUseCase) GetByID(ctx context.Context, id uint) (*Department, error)

GetByID retrieves a department by ID.

func (*DepartmentUseCase) GetDepartmentOptions

func (uc *DepartmentUseCase) GetDepartmentOptions(ctx context.Context) ([]*model.Department, error)

GetDepartmentOptions retrieves a list of departments for options.

func (*DepartmentUseCase) List

func (uc *DepartmentUseCase) List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*Department, int, error)

List returns a list of departments with pagination and filtering.

func (*DepartmentUseCase) Update

Update updates an existing department.

func (*DepartmentUseCase) UpdateEnabled

func (uc *DepartmentUseCase) UpdateEnabled(ctx context.Context, id uint, enabled bool) error

UpdateEnabled updates department enabled.

type PermissionUseCase

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

PermissionUseCase represents the permission use case

func NewPermissionUseCase

func NewPermissionUseCase() *PermissionUseCase

NewPermissionUseCase creates a new instance of PermissionUseCase

func (*PermissionUseCase) GetPermissionTree

func (uc *PermissionUseCase) GetPermissionTree(ctx context.Context) ([]*permission.Node, error)

GetPermissionTree returns the permission tree

type Role

type Role struct {
	*model.Role
	UserCount int64
}

Role contains role data

type RoleRepository

type RoleRepository interface {
	Create(ctx context.Context, role *model.Role) error
	List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*model.Role, int, error)
	IsExists(ctx context.Context, filters map[string]any, notFilters map[string]any) (bool, error)
	Count(ctx context.Context, filters map[string]any, notFilters map[string]any) (int64, error)
	FindByID(ctx context.Context, id uint) (*model.Role, error)
	Update(ctx context.Context, role *model.Role, params map[string]any) error
	Delete(ctx context.Context, id uint) error
}

RoleRepository defines methods for role data access.

type RoleUseCase

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

RoleUseCase implements business logic for role operations.

func NewRoleUseCase

func NewRoleUseCase(tx Transaction, repo RoleRepository, userRepo UserRepository) *RoleUseCase

NewRoleUseCase creates a new instance of RoleUseCase.

func (*RoleUseCase) Create

func (uc *RoleUseCase) Create(ctx context.Context, params CreateRoleParams) (uint, error)

Create creates a new role.

func (*RoleUseCase) Delete

func (uc *RoleUseCase) Delete(ctx context.Context, id uint) error

Delete removes a role.

func (*RoleUseCase) GetByID

func (uc *RoleUseCase) GetByID(ctx context.Context, id uint) (*Role, error)

GetByID retrieves a role by ID.

func (*RoleUseCase) GetRoleOptions

func (uc *RoleUseCase) GetRoleOptions(ctx context.Context) ([]*model.Role, error)

GetRoleOptions retrieves a list of roles for options.

func (*RoleUseCase) List

func (uc *RoleUseCase) List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*Role, int, error)

List returns a list of roles with pagination and filtering.

func (*RoleUseCase) Update

func (uc *RoleUseCase) Update(ctx context.Context, params UpdateRoleParams) error

Update updates an existing role.

func (*RoleUseCase) UpdateEnabled

func (uc *RoleUseCase) UpdateEnabled(ctx context.Context, id uint, enabled bool) error

UpdateEnabled updates role enabled.

func (*RoleUseCase) UpdatePermissions

func (uc *RoleUseCase) UpdatePermissions(ctx context.Context, roleID uint, permissions []string) error

UpdatePermissions updates role permissions

type Transaction

type Transaction interface {
	Transaction(ctx context.Context, fn func(ctx context.Context) error) error
}

type UpdateDepartmentParams

type UpdateDepartmentParams struct {
	ID          uint
	Name        string
	Description string

	// Fields to track which values are explicitly set
	NameSet        bool
	DescriptionSet bool
}

UpdateDepartmentParams contains all parameters needed to update a department

type UpdateRoleParams

type UpdateRoleParams struct {
	ID          uint
	Name        string
	Description string

	// Fields to track which values are explicitly set
	NameSet        bool
	DescriptionSet bool
}

UpdateRoleParams contains all parameters needed to update a role

type UpdateUserParams

type UpdateUserParams struct {
	ID           uint
	Username     string
	Password     string
	FullName     string
	PhoneNumber  string
	Email        string
	DepartmentID uint
	RoleID       uint

	// Fields to track which values are explicitly set
	UsernameSet     bool
	PasswordSet     bool
	FullNameSet     bool
	PhoneNumberSet  bool
	EmailSet        bool
	DepartmentIDSet bool
	RoleIDSet       bool
}

UpdateUserParams contains all parameters needed to update a user

type User

type User struct {
	*model.User
	RoleName       string
	RoleSlug       string
	DepartmentName string
}

type UserRepository

type UserRepository interface {
	Create(ctx context.Context, user *model.User) error
	List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*model.User, int, error)
	IsExists(ctx context.Context, filters map[string]any, notFilters map[string]any) (bool, error)
	Count(ctx context.Context, filters map[string]any, notFilters map[string]any) (int64, error)
	FindByID(ctx context.Context, id uint) (*model.User, error)
	FindByUsername(ctx context.Context, username string) (*model.User, error)
	Update(ctx context.Context, user *model.User, params map[string]any) error
	Delete(ctx context.Context, id uint) error
	SetRSAPrivateKey(ctx context.Context, cacheKey string, privateKey []byte) error
	GetRSAPrivateKey(ctx context.Context, cacheKey string) ([]byte, error)
	DeleteRSAPrivateKey(ctx context.Context, cacheKey string) error
}

UserRepository defines methods for user data access.

type UserUseCase

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

UserUseCase implements business logic for user operations.

func NewUserUseCase

func NewUserUseCase(tx Transaction, repo UserRepository, roleRepo RoleRepository, departmentRepo DepartmentRepository) *UserUseCase

NewUserUseCase creates a new instance of UserUseCase.

func (*UserUseCase) Create

func (uc *UserUseCase) Create(ctx context.Context, params CreateUserParams) (uint, error)

Create creates a new user.

func (*UserUseCase) Delete

func (uc *UserUseCase) Delete(ctx context.Context, id uint) error

Delete removes a user.

func (*UserUseCase) DeleteRSAPrivateKey

func (uc *UserUseCase) DeleteRSAPrivateKey(ctx context.Context, cacheKey string) error

func (*UserUseCase) GetByID

func (uc *UserUseCase) GetByID(ctx context.Context, id uint) (*User, error)

GetByID retrieves a user by ID.

func (*UserUseCase) GetRSAPrivateKey

func (uc *UserUseCase) GetRSAPrivateKey(ctx context.Context, cacheKey string) ([]byte, error)

func (*UserUseCase) GetRSAPublicKey

func (uc *UserUseCase) GetRSAPublicKey(ctx context.Context) (string, string, error)

func (*UserUseCase) List

func (uc *UserUseCase) List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*User, int, error)

List returns a list of users with pagination and filtering.

func (*UserUseCase) Login

func (uc *UserUseCase) Login(ctx context.Context, username, password string) (*User, error)

Login authenticates a user.

func (*UserUseCase) Update

func (uc *UserUseCase) Update(ctx context.Context, params UpdateUserParams) error

Update updates an existing user.

func (*UserUseCase) UpdateEnabled

func (uc *UserUseCase) UpdateEnabled(ctx context.Context, id uint, enabled bool) error

UpdateEnabled updates user enabled.

Jump to

Keyboard shortcuts

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