Renamed service Guard to GuardService

This commit is contained in:
2025-10-22 17:42:23 +02:00
parent ee0b512bfe
commit ad647fd1b0
5 changed files with 21 additions and 13 deletions

View File

@@ -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())
}

View File

@@ -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())

View File

@@ -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)

View File

@@ -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,
}

View File

@@ -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
}