generated from VLADIMIR/template
fix names
This commit is contained in:
@@ -48,9 +48,9 @@ type usersRepository interface {
|
||||
GetUserByEmail(ctx context.Context, email string) (*repos.User, error)
|
||||
GetUserByID(ctx context.Context, id int) (*repos.User, error)
|
||||
GetUsers(ctx context.Context) ([]*repos.User, error)
|
||||
AddUserRole(ctx context.Context, userId int, role string) error
|
||||
DeleteUserRole(ctx context.Context, userId int, role string) error
|
||||
DeleteUser(ctx context.Context, userId int) error
|
||||
AddUserRole(ctx context.Context, userID int, role string) error
|
||||
DeleteUserRole(ctx context.Context, userID int, role string) error
|
||||
DeleteUser(ctx context.Context, userID int) error
|
||||
}
|
||||
|
||||
type UsersService struct {
|
||||
@@ -165,17 +165,17 @@ func (s *UsersService) AddUser(
|
||||
// access-токена не должен мочь удалить чужой аккаунт.
|
||||
func (s *UsersService) DeleteAccount(
|
||||
ctx context.Context,
|
||||
userId int,
|
||||
userID int,
|
||||
password string,
|
||||
) error {
|
||||
user, err := s.usersRepo.GetUserByID(ctx, userId)
|
||||
user, err := s.usersRepo.GetUserByID(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password)); err != nil {
|
||||
return errors.New("Неверный пароль")
|
||||
}
|
||||
return s.usersRepo.DeleteUser(ctx, userId)
|
||||
return s.usersRepo.DeleteUser(ctx, userID)
|
||||
}
|
||||
|
||||
func (s *UsersService) RefreshPassword(
|
||||
@@ -336,9 +336,9 @@ func (s *UsersService) GetUsers(
|
||||
|
||||
func (s *UsersService) GetUserByID(
|
||||
ctx context.Context,
|
||||
userId int,
|
||||
userID int,
|
||||
) (*repos.User, error) {
|
||||
user, err := s.usersRepo.GetUserByID(ctx, userId)
|
||||
user, err := s.usersRepo.GetUserByID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -347,24 +347,24 @@ func (s *UsersService) GetUserByID(
|
||||
|
||||
func (s *UsersService) AddUserRole(
|
||||
ctx context.Context,
|
||||
userId int,
|
||||
userID int,
|
||||
role string,
|
||||
) error {
|
||||
if !slices.Contains(roles.AllRoles, role) {
|
||||
return fmt.Errorf("role %s not support", role)
|
||||
}
|
||||
return s.usersRepo.AddUserRole(ctx, userId, role)
|
||||
return s.usersRepo.AddUserRole(ctx, userID, role)
|
||||
}
|
||||
|
||||
func (s *UsersService) DeleteUserRole(
|
||||
ctx context.Context,
|
||||
userId int,
|
||||
userID int,
|
||||
role string,
|
||||
) error {
|
||||
if !slices.Contains(roles.AllRoles, role) {
|
||||
return fmt.Errorf("role %s not support", role)
|
||||
}
|
||||
return s.usersRepo.DeleteUserRole(ctx, userId, role)
|
||||
return s.usersRepo.DeleteUserRole(ctx, userID, role)
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -117,14 +117,14 @@ func (r *fakeRepo) AddUserRole(_ context.Context, _ int, _ string) error { retur
|
||||
|
||||
func (r *fakeRepo) DeleteUserRole(_ context.Context, _ int, _ string) error { return nil }
|
||||
|
||||
func (r *fakeRepo) DeleteUser(_ context.Context, userId int) error {
|
||||
func (r *fakeRepo) DeleteUser(_ context.Context, userID int) error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
u, ok := r.byID[userId]
|
||||
u, ok := r.byID[userID]
|
||||
if !ok {
|
||||
return users_repo.ErrUserNotFound
|
||||
}
|
||||
delete(r.byID, userId)
|
||||
delete(r.byID, userID)
|
||||
delete(r.users, u.Email)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user