Documentation
¶
Overview ¶
Package usecase contains business logic.
Package usecase contains business logic.
Package usecase contains business logic.
Package usecase provides business logic implementations.
Index ¶
- Variables
- type CreateDepartmentParams
- type CreateRoleParams
- type CreateUserParams
- type Department
- type DepartmentRepository
- type DepartmentUseCase
- func (uc *DepartmentUseCase) Create(ctx context.Context, params CreateDepartmentParams) (uint, error)
- func (uc *DepartmentUseCase) Delete(ctx context.Context, id uint) error
- func (uc *DepartmentUseCase) GetByID(ctx context.Context, id uint) (*Department, error)
- func (uc *DepartmentUseCase) GetDepartmentOptions(ctx context.Context) ([]*model.Department, error)
- func (uc *DepartmentUseCase) List(ctx context.Context, filters map[string]any, limit, offset int, ...) ([]*Department, int, error)
- func (uc *DepartmentUseCase) Update(ctx context.Context, params UpdateDepartmentParams) error
- func (uc *DepartmentUseCase) UpdateEnabled(ctx context.Context, id uint, enabled bool) error
- type PermissionUseCase
- type Role
- type RoleRepository
- type RoleUseCase
- func (uc *RoleUseCase) Create(ctx context.Context, params CreateRoleParams) (uint, error)
- func (uc *RoleUseCase) Delete(ctx context.Context, id uint) error
- func (uc *RoleUseCase) GetByID(ctx context.Context, id uint) (*Role, error)
- func (uc *RoleUseCase) GetRoleOptions(ctx context.Context) ([]*model.Role, error)
- func (uc *RoleUseCase) List(ctx context.Context, filters map[string]any, limit, offset int, ...) ([]*Role, int, error)
- func (uc *RoleUseCase) Update(ctx context.Context, params UpdateRoleParams) error
- func (uc *RoleUseCase) UpdateEnabled(ctx context.Context, id uint, enabled bool) error
- func (uc *RoleUseCase) UpdatePermissions(ctx context.Context, roleID uint, permissions []string) error
- type Transaction
- type UpdateDepartmentParams
- type UpdateRoleParams
- type UpdateUserParams
- type User
- type UserRepository
- type UserUseCase
- func (uc *UserUseCase) Create(ctx context.Context, params CreateUserParams) (uint, error)
- func (uc *UserUseCase) Delete(ctx context.Context, id uint) error
- func (uc *UserUseCase) DeleteRSAPrivateKey(ctx context.Context, cacheKey string) error
- func (uc *UserUseCase) GetByID(ctx context.Context, id uint) (*User, error)
- func (uc *UserUseCase) GetRSAPrivateKey(ctx context.Context, cacheKey string) ([]byte, error)
- func (uc *UserUseCase) GetRSAPublicKey(ctx context.Context) (string, string, error)
- func (uc *UserUseCase) List(ctx context.Context, filters map[string]any, limit, offset int, ...) ([]*User, int, error)
- func (uc *UserUseCase) Login(ctx context.Context, username, password string) (*User, error)
- func (uc *UserUseCase) Update(ctx context.Context, params UpdateUserParams) error
- func (uc *UserUseCase) UpdateEnabled(ctx context.Context, id uint, enabled bool) error
Constants ¶
This section is empty.
Variables ¶
var ProviderSet = wire.NewSet( NewDepartmentUseCase, NewPermissionUseCase, NewRoleUseCase, NewUserUseCase, )
ProviderSet provides all usecase layer dependencies.
Functions ¶
This section is empty.
Types ¶
type CreateDepartmentParams ¶
CreateDepartmentParams contains all parameters needed to create a department
type CreateRoleParams ¶
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 ¶
func (uc *DepartmentUseCase) Create(ctx context.Context, params CreateDepartmentParams) (uint, error)
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 ¶
func (uc *DepartmentUseCase) Update(ctx context.Context, params UpdateDepartmentParams) error
Update updates an existing department.
func (*DepartmentUseCase) UpdateEnabled ¶
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 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) GetRoleOptions ¶
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 ¶
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 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 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) GetRSAPrivateKey ¶
func (*UserUseCase) GetRSAPublicKey ¶
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) Update ¶
func (uc *UserUseCase) Update(ctx context.Context, params UpdateUserParams) error
Update updates an existing user.
func (*UserUseCase) UpdateEnabled ¶
UpdateEnabled updates user enabled.