Renamed service Guard to GuardService
This commit is contained in:
@@ -15,10 +15,14 @@ func (s *Server) LoginHandlerFn(c *fiber.Ctx) error {
|
|||||||
return s.Error(c, fiber.StatusBadRequest, "Error parsing input")
|
return s.Error(c, fiber.StatusBadRequest, "Error parsing input")
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := domain.NewUserRepository(s.GetDatabase())
|
userRepo := domain.NewUserRepository(s.GetDatabase())
|
||||||
authSrv := service.NewAuthService(repo, s.GetCache())
|
roleRepo := domain.NewRoleRepository(s.GetDatabase())
|
||||||
token, err := ui.NewLoginActionUI(authSrv).Execute(data)
|
urlRepo := domain.NewURLAccessRepository(s.GetDatabase())
|
||||||
if err != nil { // TODO: handle other response status codes
|
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())
|
return s.Error(c, fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ func (s *Server) RegisterHandlerFn(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repo := domain.NewUserRepository(s.GetDatabase())
|
repo := domain.NewUserRepository(s.GetDatabase())
|
||||||
|
|
||||||
id, err := ui.NewRegisterActionUI(repo, s.GetCache()).Execute(data)
|
id, err := ui.NewRegisterActionUI(repo, s.GetCache()).Execute(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.Error(c, fiber.StatusBadRequest, err.Error())
|
return s.Error(c, fiber.StatusBadRequest, err.Error())
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ import (
|
|||||||
domain "git.ego.freeddns.org/egommerce/identity-service/domain/repository"
|
domain "git.ego.freeddns.org/egommerce/identity-service/domain/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Guard struct {
|
type GuardService struct {
|
||||||
authSrv *AuthService
|
authSrv *AuthService
|
||||||
userRepo *domain.UserRepository
|
userRepo *domain.UserRepository
|
||||||
roleRepo *domain.RoleRepository
|
roleRepo *domain.RoleRepository
|
||||||
urlRepo *domain.URLAccessRepository
|
urlRepo *domain.URLAccessRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGuardService(authSrv *AuthService, userRepo *domain.UserRepository, roleRepo *domain.RoleRepository, urlRepo *domain.URLAccessRepository) *Guard {
|
func NewGuardService(authSrv *AuthService, userRepo *domain.UserRepository, roleRepo *domain.RoleRepository, urlRepo *domain.URLAccessRepository) *GuardService {
|
||||||
return &Guard{
|
return &GuardService{
|
||||||
authSrv: authSrv,
|
authSrv: authSrv,
|
||||||
userRepo: userRepo,
|
userRepo: userRepo,
|
||||||
roleRepo: roleRepo,
|
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)
|
token, _ := g.authSrv.GetTokenFromAuthorizationHeader(authHeader)
|
||||||
|
|
||||||
uid, _ := g.authSrv.getUIDByAccesssToken(token)
|
uid, _ := g.authSrv.getUIDByAccesssToken(token)
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AccessActionUI struct {
|
type AccessActionUI struct {
|
||||||
guard *service.Guard
|
guard *service.GuardService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccessActionUI(guard *service.Guard) *AccessActionUI {
|
func NewAccessActionUI(guard *service.GuardService) *AccessActionUI {
|
||||||
return &AccessActionUI{
|
return &AccessActionUI{
|
||||||
guard: guard,
|
guard: guard,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type LoginActionUI struct {
|
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{
|
return &LoginActionUI{
|
||||||
authSrv: authSrv,
|
authSrv: authSrv,
|
||||||
|
guardSrv: guardSrv,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *LoginActionUI) Execute(data *dto.AuthLoginRequestDTO) (string, error) {
|
func (ui *LoginActionUI) Execute(data *dto.AuthLoginRequestDTO) (string, error) {
|
||||||
token, err := ui.authSrv.Login(data.Username, data.Password)
|
token, err := ui.authSrv.Login(data.Username, data.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// TODO: handle other response status codes -- add struct to decorate error with code and message
|
||||||
if err == service.ErrUnableToCacheToken {
|
if err == service.ErrUnableToCacheToken {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user