Browse Source

refact: change Authentication service layer to be a pointer, same with Authentication API and CLI controllers

Matheus Marques Polillo 1 year ago
parent
commit
bd28a7cfbc

+ 4 - 4
src/presentation/api/controller/authentication.go

@@ -7,11 +7,11 @@ import (
 )
 
 type AuthController struct {
-	authService service.AuthService
+	authService *service.AuthService
 }
 
-func NewAuthController() AuthController {
-	return AuthController{
+func NewAuthController() *AuthController {
+	return &AuthController{
 		authService: service.NewAuthService(),
 	}
 }
@@ -26,7 +26,7 @@ func NewAuthController() AuthController {
 // @Success      200 {object} entity.AccessToken
 // @Failure      401 {object} string
 // @Router       /v1/auth/login/ [post]
-func (controller AuthController) GenerateJwtWithCredentials(c echo.Context) error {
+func (controller *AuthController) GenerateJwtWithCredentials(c echo.Context) error {
 	requestBody, err := apiHelper.ReadRequestBody(c)
 	if err != nil {
 		return err

+ 4 - 4
src/presentation/cli/controller/authentication.go

@@ -7,16 +7,16 @@ import (
 )
 
 type AuthController struct {
-	authService service.AuthService
+	authService *service.AuthService
 }
 
-func NewAuthController() AuthController {
-	return AuthController{
+func NewAuthController() *AuthController {
+	return &AuthController{
 		authService: service.NewAuthService(),
 	}
 }
 
-func (controller AuthController) Login() *cobra.Command {
+func (controller *AuthController) Login() *cobra.Command {
 	var usernameStr string
 	var passwordStr string
 	var ipAddressStr string

+ 4 - 7
src/presentation/service/authentication.go

@@ -12,11 +12,11 @@ import (
 type AuthService struct {
 }
 
-func NewAuthService() AuthService {
-	return AuthService{}
+func NewAuthService() *AuthService {
+	return &AuthService{}
 }
 
-func (service AuthService) GenerateJwtWithCredentials(
+func (service *AuthService) GenerateJwtWithCredentials(
 	input map[string]interface{},
 ) ServiceOutput {
 	requiredParams := []string{"username", "password", "ipAddress"}
@@ -47,10 +47,7 @@ func (service AuthService) GenerateJwtWithCredentials(
 	accQueryRepo := accountInfra.AccQueryRepo{}
 
 	accessToken, err := useCase.GetSessionToken(
-		authQueryRepo,
-		authCmdRepo,
-		accQueryRepo,
-		dto,
+		authQueryRepo, authCmdRepo, accQueryRepo, dto,
 	)
 	if err != nil {
 		return NewServiceOutput(InfraError, err.Error())