Добавлен основные классы для сервиса авторизаци

This commit is contained in:
Ганеев Артем
2025-10-28 20:49:54 +03:00
parent def3552a67
commit 736b8031f8
26 changed files with 904 additions and 40 deletions

44
internal/service/user.go Normal file
View File

@@ -0,0 +1,44 @@
package service
import (
"authorization/internal"
"authorization/internal/repository"
)
type UserService interface {
CreateUser(internal.User) (int, error)
ChangeUserRole(username string, Role string) (string, error)
GetUser(username string, hashedPassword string) (*internal.User, error)
}
type UserServiceImpl struct {
repo repository.UserResository
}
func newUserService(repo repository.UserResository) *UserServiceImpl {
return &UserServiceImpl{repo: repo}
}
func (s *UserServiceImpl) CreateUser(user internal.User) (int, error) {
return s.repo.CreateUser(user)
}
func (s *UserServiceImpl) ChangeUserRole(username string, userRole string) (string, error) {
newRole, err := internal.FromString(userRole)
if err != nil {
return "", err
}
user, err := s.repo.UpdateUserRole(username, newRole)
if err != nil {
return "", err
}
return user, nil
}
func (s *UserServiceImpl) GetUser(username string, hashedPassword string) (*internal.User, error) {
user, err := s.repo.GetUser(username, hashedPassword)
if err != nil {
return nil, err
}
return &user, nil
}