Pārlūkot izejas kodu

refact: implements new Authentication service layer to Authentication CLI controller

Matheus Marques Polillo 1 gadu atpakaļ
vecāks
revīzija
3a61664fcf
1 mainītis faili ar 17 papildinājumiem un 26 dzēšanām
  1. 17 26
      src/presentation/cli/controller/authentication.go

+ 17 - 26
src/presentation/cli/controller/authentication.go

@@ -1,19 +1,22 @@
 package cliController
 
 import (
-	"github.com/speedianet/os/src/domain/dto"
-	"github.com/speedianet/os/src/domain/useCase"
-	"github.com/speedianet/os/src/domain/valueObject"
-	accountInfra "github.com/speedianet/os/src/infra/account"
-	authInfra "github.com/speedianet/os/src/infra/auth"
 	cliHelper "github.com/speedianet/os/src/presentation/cli/helper"
+	"github.com/speedianet/os/src/presentation/service"
 	"github.com/spf13/cobra"
 )
 
-type AuthenticationController struct {
+type AuthController struct {
+	authService service.AuthService
 }
 
-func (controller *AuthenticationController) Login() *cobra.Command {
+func NewAuthController() AuthController {
+	return AuthController{
+		authService: service.NewAuthService(),
+	}
+}
+
+func (controller AuthController) Login() *cobra.Command {
 	var usernameStr string
 	var passwordStr string
 	var ipAddressStr string
@@ -22,27 +25,15 @@ func (controller *AuthenticationController) Login() *cobra.Command {
 		Use:   "login",
 		Short: "Login",
 		Run: func(cmd *cobra.Command, args []string) {
-			username := valueObject.NewUsernamePanic(usernameStr)
-			password := valueObject.NewPasswordPanic(passwordStr)
-			ipAddress := valueObject.NewIpAddressPanic(ipAddressStr)
-
-			loginDto := dto.NewLogin(username, password, ipAddress)
-
-			authQueryRepo := authInfra.AuthQueryRepo{}
-			authCmdRepo := authInfra.AuthCmdRepo{}
-			accQueryRepo := accountInfra.AccQueryRepo{}
-
-			accessToken, err := useCase.GetSessionToken(
-				authQueryRepo,
-				authCmdRepo,
-				accQueryRepo,
-				loginDto,
-			)
-			if err != nil {
-				cliHelper.ResponseWrapper(false, err.Error())
+			requestBody := map[string]interface{}{
+				"username":  usernameStr,
+				"password":  passwordStr,
+				"ipAddress": ipAddressStr,
 			}
 
-			cliHelper.ResponseWrapper(true, accessToken)
+			cliHelper.ServiceResponseWrapper(
+				controller.authService.GenerateJwtWithCredentials(requestBody),
+			)
 		},
 	}