优化
This commit is contained in:
+24
-25
@@ -15,20 +15,29 @@ type UserInput struct {
|
||||
AuthorityIDs []uint
|
||||
}
|
||||
|
||||
type UserService struct {
|
||||
uc *biz.UserUsecase
|
||||
settings *SettingsService
|
||||
}
|
||||
|
||||
func NewUserService(uc *biz.UserUsecase, settings *SettingsService) *UserService {
|
||||
return &UserService{uc: uc, settings: settings}
|
||||
}
|
||||
|
||||
func userInput(value *dto.UserRequest) UserInput {
|
||||
return UserInput{ID: value.ID, Username: value.Username, Password: value.Password, NickName: value.NickName, HeaderImg: value.HeaderImg, AuthorityID: value.AuthorityID, AuthorityIDs: value.AuthorityIDs, Enable: value.Enable, Phone: value.Phone, Email: value.Email}
|
||||
}
|
||||
func (s *SystemService) ListUsersRequest(ctx context.Context, value *dto.UserListRequest) ([]map[string]any, int64, error) {
|
||||
func (s *UserService) ListUsersRequest(ctx context.Context, value *dto.UserListRequest) ([]map[string]any, int64, error) {
|
||||
return s.ListUsers(ctx, value.Page, value.PageSize, &biz.UserListFilter{Username: value.Username, NickName: value.NickName, Phone: value.Phone, Email: value.Email, OrderKey: value.OrderKey, Desc: value.Desc})
|
||||
}
|
||||
func (s *SystemService) CreateUserRequest(ctx context.Context, value *dto.UserRequest) (map[string]any, error) {
|
||||
func (s *UserService) CreateUserRequest(ctx context.Context, value *dto.UserRequest) (map[string]any, error) {
|
||||
return s.CreateUser(ctx, userInput(value))
|
||||
}
|
||||
func (s *SystemService) UpdateUserRequest(ctx context.Context, value *dto.UserRequest) error {
|
||||
func (s *UserService) UpdateUserRequest(ctx context.Context, value *dto.UserRequest) error {
|
||||
return s.UpdateUser(ctx, userInput(value))
|
||||
}
|
||||
|
||||
func (s *SystemService) User(ctx context.Context, id uint) (map[string]any, error) {
|
||||
func (s *UserService) User(ctx context.Context, id uint) (map[string]any, error) {
|
||||
value, err := s.uc.User(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -36,7 +45,7 @@ func (s *SystemService) User(ctx context.Context, id uint) (map[string]any, erro
|
||||
return convertUser(value), nil
|
||||
}
|
||||
|
||||
func (s *SystemService) Menus(ctx context.Context, authorityID uint) ([]map[string]any, error) {
|
||||
func (s *UserService) Menus(ctx context.Context, authorityID uint) ([]map[string]any, error) {
|
||||
menus, err := s.uc.Menus(ctx, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -48,7 +57,7 @@ func (s *SystemService) Menus(ctx context.Context, authorityID uint) ([]map[stri
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *SystemService) ListUsers(ctx context.Context, page, pageSize int, filter *biz.UserListFilter) ([]map[string]any, int64, error) {
|
||||
func (s *UserService) ListUsers(ctx context.Context, page, pageSize int, filter *biz.UserListFilter) ([]map[string]any, int64, error) {
|
||||
users, total, err := s.uc.ListUsers(ctx, page, pageSize, filter)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -60,7 +69,7 @@ func (s *SystemService) ListUsers(ctx context.Context, page, pageSize int, filte
|
||||
return result, total, nil
|
||||
}
|
||||
|
||||
func (s *SystemService) Authorities(ctx context.Context) ([]map[string]any, error) {
|
||||
func (s *UserService) Authorities(ctx context.Context) ([]map[string]any, error) {
|
||||
values, err := s.uc.Authorities(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -72,7 +81,7 @@ func (s *SystemService) Authorities(ctx context.Context) ([]map[string]any, erro
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *SystemService) CreateUser(ctx context.Context, input UserInput) (map[string]any, error) {
|
||||
func (s *UserService) CreateUser(ctx context.Context, input UserInput) (map[string]any, error) {
|
||||
if err := s.settings.ValidatePassword(ctx, input.Password); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -84,41 +93,31 @@ func (s *SystemService) CreateUser(ctx context.Context, input UserInput) (map[st
|
||||
}
|
||||
return convertUser(user), nil
|
||||
}
|
||||
func (s *SystemService) UpdateUser(ctx context.Context, input UserInput) error {
|
||||
func (s *UserService) UpdateUser(ctx context.Context, input UserInput) error {
|
||||
return s.uc.UpdateUser(ctx, &biz.User{ID: input.ID, NickName: input.NickName, HeaderImg: input.HeaderImg, AuthorityID: input.AuthorityID, Phone: input.Phone, Email: input.Email, Enable: input.Enable}, input.AuthorityIDs)
|
||||
}
|
||||
func (s *SystemService) UpdateSelfUser(ctx context.Context, input UserInput) error {
|
||||
func (s *UserService) UpdateSelfUser(ctx context.Context, input UserInput) error {
|
||||
return s.uc.UpdateSelfUser(ctx, &biz.User{ID: input.ID, NickName: input.NickName, HeaderImg: input.HeaderImg, Phone: input.Phone, Email: input.Email, Enable: input.Enable})
|
||||
}
|
||||
func (s *SystemService) DeleteUser(ctx context.Context, id uint) error {
|
||||
func (s *UserService) DeleteUser(ctx context.Context, id uint) error {
|
||||
return s.uc.DeleteUser(ctx, id)
|
||||
}
|
||||
func (s *SystemService) ResetPassword(ctx context.Context, id uint, password string) error {
|
||||
func (s *UserService) ResetPassword(ctx context.Context, id uint, password string) error {
|
||||
if err := s.settings.ValidatePassword(ctx, password); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.uc.ResetPassword(ctx, id, password)
|
||||
}
|
||||
func (s *SystemService) ChangePassword(ctx context.Context, id uint, oldPassword, newPassword string) error {
|
||||
func (s *UserService) ChangePassword(ctx context.Context, id uint, oldPassword, newPassword string) error {
|
||||
if err := s.settings.ValidatePassword(ctx, newPassword); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.uc.ChangePassword(ctx, id, oldPassword, newPassword)
|
||||
}
|
||||
|
||||
func (s *SystemService) SetUserAuthorities(ctx context.Context, id uint, authorityIDs []uint) error {
|
||||
func (s *UserService) SetUserAuthorities(ctx context.Context, id uint, authorityIDs []uint) error {
|
||||
return s.uc.SetUserAuthorities(ctx, id, authorityIDs)
|
||||
}
|
||||
func (s *SystemService) SwitchAuthority(ctx context.Context, id, authorityID uint) (*LoginResult, error) {
|
||||
if err := s.uc.SetUserAuthority(ctx, id, authorityID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := s.uc.User(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.issueLogin(ctx, user, authorityID)
|
||||
}
|
||||
func (s *SystemService) SetUserSetting(ctx context.Context, id uint, setting map[string]any) error {
|
||||
func (s *UserService) SetUserSetting(ctx context.Context, id uint, setting map[string]any) error {
|
||||
return s.uc.SetUserSetting(ctx, id, setting)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user