diff --git a/src/internal/server/login_handler.go b/src/internal/server/login_handler.go index df8cd5c..1bf5b8e 100644 --- a/src/internal/server/login_handler.go +++ b/src/internal/server/login_handler.go @@ -15,10 +15,14 @@ func (s *Server) LoginHandlerFn(c *fiber.Ctx) error { return s.Error(c, fiber.StatusBadRequest, "Error parsing input") } - repo := domain.NewUserRepository(s.GetDatabase()) - authSrv := service.NewAuthService(repo, s.GetCache()) - token, err := ui.NewLoginActionUI(authSrv).Execute(data) - if err != nil { // TODO: handle other response status codes + userRepo := domain.NewUserRepository(s.GetDatabase()) + roleRepo := domain.NewRoleRepository(s.GetDatabase()) + urlRepo := domain.NewURLAccessRepository(s.GetDatabase()) + authSrv := service.NewAuthService(userRepo, s.GetCache()) + guardSrv := service.NewGuardService(authSrv, userRepo, roleRepo, urlRepo) + + token, err := ui.NewLoginActionUI(authSrv, guardSrv).Execute(data) + if err != nil { // TODO: handle other response status codes -- add struct to decorate error with code and message return s.Error(c, fiber.StatusBadRequest, err.Error()) } diff --git a/src/internal/server/register_handler.go b/src/internal/server/register_handler.go index 8180a69..5863bed 100644 --- a/src/internal/server/register_handler.go +++ b/src/internal/server/register_handler.go @@ -15,6 +15,7 @@ func (s *Server) RegisterHandlerFn(c *fiber.Ctx) error { } repo := domain.NewUserRepository(s.GetDatabase()) + id, err := ui.NewRegisterActionUI(repo, s.GetCache()).Execute(data) if err != nil { return s.Error(c, fiber.StatusBadRequest, err.Error()) diff --git a/src/internal/service/guard.go b/src/internal/service/guard.go index a182b56..39c8115 100644 --- a/src/internal/service/guard.go +++ b/src/internal/service/guard.go @@ -7,15 +7,15 @@ import ( domain "git.ego.freeddns.org/egommerce/identity-service/domain/repository" ) -type Guard struct { +type GuardService struct { authSrv *AuthService userRepo *domain.UserRepository roleRepo *domain.RoleRepository urlRepo *domain.URLAccessRepository } -func NewGuardService(authSrv *AuthService, userRepo *domain.UserRepository, roleRepo *domain.RoleRepository, urlRepo *domain.URLAccessRepository) *Guard { - return &Guard{ +func NewGuardService(authSrv *AuthService, userRepo *domain.UserRepository, roleRepo *domain.RoleRepository, urlRepo *domain.URLAccessRepository) *GuardService { + return &GuardService{ authSrv: authSrv, userRepo: userRepo, roleRepo: roleRepo, @@ -23,7 +23,7 @@ func NewGuardService(authSrv *AuthService, userRepo *domain.UserRepository, role } } -func (g *Guard) CheckUserPermissions(authHeader *dto.AuthorizationHeaderDTO, url, srvName string) error { +func (g *GuardService) CheckUserPermissions(authHeader *dto.AuthorizationHeaderDTO, url, srvName string) error { token, _ := g.authSrv.GetTokenFromAuthorizationHeader(authHeader) uid, _ := g.authSrv.getUIDByAccesssToken(token) diff --git a/src/internal/ui/access_action.go b/src/internal/ui/access_action.go index 5e19de2..632561d 100644 --- a/src/internal/ui/access_action.go +++ b/src/internal/ui/access_action.go @@ -6,10 +6,10 @@ import ( ) type AccessActionUI struct { - guard *service.Guard + guard *service.GuardService } -func NewAccessActionUI(guard *service.Guard) *AccessActionUI { +func NewAccessActionUI(guard *service.GuardService) *AccessActionUI { return &AccessActionUI{ guard: guard, } diff --git a/src/internal/ui/login_action.go b/src/internal/ui/login_action.go index 29d9f2b..8f09401 100644 --- a/src/internal/ui/login_action.go +++ b/src/internal/ui/login_action.go @@ -6,18 +6,21 @@ import ( ) type LoginActionUI struct { - authSrv *service.AuthService + authSrv *service.AuthService + guardSrv *service.GuardService } -func NewLoginActionUI(authSrv *service.AuthService) *LoginActionUI { +func NewLoginActionUI(authSrv *service.AuthService, guardSrv *service.GuardService) *LoginActionUI { return &LoginActionUI{ - authSrv: authSrv, + authSrv: authSrv, + guardSrv: guardSrv, } } func (ui *LoginActionUI) Execute(data *dto.AuthLoginRequestDTO) (string, error) { token, err := ui.authSrv.Login(data.Username, data.Password) if err != nil { + // TODO: handle other response status codes -- add struct to decorate error with code and message if err == service.ErrUnableToCacheToken { return "", err }