add roles routes

This commit is contained in:
2026-07-06 23:32:38 +07:00
parent 728fcc6fda
commit 82ffda5c0a
9 changed files with 1029 additions and 39 deletions
@@ -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)
}