generated from VLADIMIR/template
add roles routes
This commit is contained in:
@@ -6,10 +6,12 @@ import (
|
||||
"evening_detective_server/internal/modules/email_sender"
|
||||
"evening_detective_server/internal/modules/password_generator"
|
||||
"evening_detective_server/internal/modules/processor_jwt"
|
||||
"evening_detective_server/internal/modules/roles"
|
||||
"evening_detective_server/internal/repos"
|
||||
"evening_detective_server/internal/repos/refresh_tokens_repo"
|
||||
"evening_detective_server/internal/repos/users_repo"
|
||||
"fmt"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -208,3 +210,25 @@ func (s *UsersService) GetUserByID(
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (s *UsersService) AddUserRole(
|
||||
ctx context.Context,
|
||||
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)
|
||||
}
|
||||
|
||||
func (s *UsersService) DeleteUserRole(
|
||||
ctx context.Context,
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user