service

package
v2.0.17 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoleNotFound = apperr.New("role_not_found",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Роль не найдена", translator.EN: "Role not found"}),
		apperr.WithCode(code.NotFound),
	)
	ErrRoleExists = apperr.New("role_exists_error",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Роль уже добавлена", translator.EN: "Role has already been added"}),
		apperr.WithCode(code.InvalidArgument),
	)
	ErrRoleCannotBeChanged = apperr.New("role_cannot_be_changed",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Роль нельзя редактировать", translator.EN: "Role cannot be changed"}),
		apperr.WithCode(code.PermissionDenied),
	)
	ErrRoleCannotBeDeleted = apperr.New("role_cannot_be_deleted",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Роль нельзя удалять", translator.EN: "Role cannot be deleted"}),
		apperr.WithCode(code.PermissionDenied),
	)
)
View Source
var (
	ErrUserNotFound = apperr.New("user_not_found",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Пользователь не найден", translator.EN: "User not found"}),
		apperr.WithCode(code.NotFound),
	)
	ErrUserExists = apperr.New("user_exists_error",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Пользователь с таким логином уже зарегистрирован", translator.EN: "A user with this login is already registered"}),
		apperr.WithCode(code.InvalidArgument),
	)
	ErrUserRolesCannotBeChanged = apperr.New("user_roles_cannot_be_changed",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Нельзя назначать пользователю другие роли", translator.EN: "User roles cannot be changed"}),
		apperr.WithCode(code.PermissionDenied),
	)
	ErrUserCannotBeDeleted = apperr.New("user_cannot_be_deleted",
		apperr.WithTextTranslate(translator.Translate{translator.RU: "Пользователя нельзя удалять", translator.EN: "User cannot be deleted"}),
		apperr.WithCode(code.PermissionDenied),
	)
)

Functions

This section is empty.

Types

type AuthLogin

type AuthLogin struct {
	Login    string
	Password string
	DeviceID int
}

type AuthLogout

type AuthLogout struct {
	Token string
}

type AuthRefresh

type AuthRefresh struct {
	Token    string
	DeviceID int
}

type AuthService

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

func NewAuthService

func NewAuthService(
	userRepository repository.IUserRepository,
	tokenRepository repository.ITokenRepository,
	tokenCache cache.ITokenCache,
	userCache cache.IUserCache,
	hasher secret.Hasher,
	accessExpire time.Duration,
	refreshExpire time.Duration,
	accessSecret string,
) AuthService

func (AuthService) Account

func (s AuthService) Account(ctx context.Context) (*model.User, error)

func (AuthService) Login

func (s AuthService) Login(ctx context.Context, input AuthLogin) (*model.AuthToken, error)

func (AuthService) Logout

func (s AuthService) Logout(ctx context.Context, input AuthLogout) error

func (AuthService) Refresh

func (s AuthService) Refresh(ctx context.Context, input AuthRefresh) (*model.AuthToken, error)

func (AuthService) Trx

func (s AuthService) Trx(db *gorm.DB) IAuthService

func (AuthService) UpdateAccountData added in v2.0.12

func (s AuthService) UpdateAccountData(ctx context.Context, input AuthUpdateAccountData) error

type AuthUpdateAccountData added in v2.0.12

type AuthUpdateAccountData struct {
	Login      *string
	FirstName  *string
	SecondName *string
	LastName   *string
	Password   *string
	Email      *string
	Phone      *string
}

type IAuthService

type IAuthService interface {
	Trx(db *gorm.DB) IAuthService
	Login(ctx context.Context, input AuthLogin) (*model.AuthToken, error)
	Refresh(ctx context.Context, input AuthRefresh) (*model.AuthToken, error)
	Logout(ctx context.Context, input AuthLogout) error
	Account(ctx context.Context) (*model.User, error)
	UpdateAccountData(ctx context.Context, input AuthUpdateAccountData) error
}

type IPermissionService added in v2.0.4

type IPermissionService interface {
	Trx(db *gorm.DB) IPermissionService
	List(ctx context.Context) ([]model.Permission, error)
}

type IRoleService added in v2.0.4

type IRoleService interface {
	Trx(db *gorm.DB) IRoleService
	List(ctx context.Context, m *model2.Meta[model.Role]) error
	GetById(ctx context.Context, id int) (*model.Role, error)
	Create(ctx context.Context, input RoleCreateInput) (*model.Role, error)
	Update(ctx context.Context, id int, input RoleUpdateInput) error
	Delete(ctx context.Context, id int) error
}

type IUserService added in v2.0.4

type IUserService interface {
	Trx(db *gorm.DB) IUserService
	List(ctx context.Context, m *model2.Meta[model.User]) error
	GetById(ctx context.Context, id int) (*model.User, error)
	Create(ctx context.Context, input UserCreateInput) (*model.User, error)
	Update(ctx context.Context, id int, input UserUpdateInput) error
	Delete(ctx context.Context, id int) error
}

type PermissionService added in v2.0.4

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

func NewPermissionService added in v2.0.4

func NewPermissionService(
	permissionRepository repository.IPermissionRepository,
	permissionCache cache.IPermissionCache,
) PermissionService

func (PermissionService) List added in v2.0.4

func (PermissionService) Trx added in v2.0.4

type RoleCreateInput added in v2.0.4

type RoleCreateInput struct {
	Name        string
	Permissions RolePermissions
}

type RolePermissions added in v2.0.4

type RolePermissions struct {
	Write []int
	Read  []int
	Exec  []int
}

type RoleService added in v2.0.4

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

func NewRoleService added in v2.0.4

func NewRoleService(
	roleRepository repository.IRoleRepository,
	permissionRepository repository.IPermissionRepository,
	rolePermissionRepository repository.IRolePermissionRepository,
	userRoleRepository repository.IUserRoleRepository,
	userCache cache.IUserCache,
	tokenCache cache.ITokenCache,
) RoleService

func (RoleService) Create added in v2.0.4

func (s RoleService) Create(ctx context.Context, input RoleCreateInput) (*model.Role, error)

func (RoleService) Delete added in v2.0.4

func (s RoleService) Delete(ctx context.Context, id int) error

func (RoleService) GetById added in v2.0.4

func (s RoleService) GetById(ctx context.Context, id int) (*model.Role, error)

func (RoleService) List added in v2.0.4

func (s RoleService) List(ctx context.Context, m *model2.Meta[model.Role]) error

func (RoleService) Trx added in v2.0.4

func (s RoleService) Trx(db *gorm.DB) IRoleService

func (RoleService) Update added in v2.0.4

func (s RoleService) Update(ctx context.Context, id int, input RoleUpdateInput) error

type RoleUpdateInput added in v2.0.4

type RoleUpdateInput struct {
	Name        *string
	Permissions *RolePermissions
}

type UserCreateInput added in v2.0.4

type UserCreateInput struct {
	Login      string
	FirstName  string
	SecondName *string
	LastName   *string
	Password   string
	Email      *string
	Phone      *string
	Roles      []int
}

type UserService added in v2.0.4

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

func NewUserService added in v2.0.4

func NewUserService(
	userRepository repository.IUserRepository,
	roleRepository repository.IRoleRepository,
	userRoleRepository repository.IUserRoleRepository,
	userCache cache.IUserCache,
	tokenCache cache.ITokenCache,
	hasher secret.Hasher,
) UserService

func (UserService) Create added in v2.0.4

func (s UserService) Create(ctx context.Context, input UserCreateInput) (*model.User, error)

func (UserService) Delete added in v2.0.4

func (s UserService) Delete(ctx context.Context, id int) error

func (UserService) GetById added in v2.0.4

func (s UserService) GetById(ctx context.Context, id int) (*model.User, error)

func (UserService) List added in v2.0.4

func (s UserService) List(ctx context.Context, m *model2.Meta[model.User]) error

func (UserService) Trx added in v2.0.4

func (s UserService) Trx(db *gorm.DB) IUserService

func (UserService) Update added in v2.0.4

func (s UserService) Update(ctx context.Context, id int, input UserUpdateInput) error

type UserUpdateInput added in v2.0.4

type UserUpdateInput struct {
	Login      *string
	FirstName  *string
	SecondName *string
	LastName   *string
	Password   *string
	Email      *string
	Phone      *string
	Roles      *[]int
}

Jump to

Keyboard shortcuts

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