Добавлен основные классы для сервиса авторизаци
This commit is contained in:
44
internal/service/user.go
Normal file
44
internal/service/user.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user