Explorar el Código

feat: add trail database service to OS root and propagating the database service instance throughout all OS

Matheus Marques Polillo hace 1 año
padre
commit
981ad8faa4

+ 2 - 1
src/presentation/api/api.go

@@ -36,6 +36,7 @@ func ApiInit(
 	e *echo.Echo,
 	persistentDbSvc *internalDbInfra.PersistentDatabaseService,
 	transientDbSvc *internalDbInfra.TransientDatabaseService,
+	trailDbSvc *internalDbInfra.TrailDatabaseService,
 ) {
 	baseRoute := e.Group(ApiBasePath)
 
@@ -51,6 +52,6 @@ func ApiInit(
 	e.Use(apiMiddleware.ReadOnlyMode(ApiBasePath))
 	e.Use(apiMiddleware.Auth(ApiBasePath))
 
-	router := NewRouter(baseRoute, transientDbSvc, persistentDbSvc)
+	router := NewRouter(baseRoute, transientDbSvc, persistentDbSvc, trailDbSvc)
 	router.RegisterRoutes()
 }

+ 5 - 2
src/presentation/api/controller/authentication.go

@@ -2,6 +2,7 @@ package apiController
 
 import (
 	"github.com/labstack/echo/v4"
+	internalDbInfra "github.com/speedianet/os/src/infra/internalDatabase"
 	apiHelper "github.com/speedianet/os/src/presentation/api/helper"
 	"github.com/speedianet/os/src/presentation/service"
 )
@@ -10,9 +11,11 @@ type AuthController struct {
 	authService *service.AuthService
 }
 
-func NewAuthController() *AuthController {
+func NewAuthController(
+	trailDbSvc *internalDbInfra.TrailDatabaseService,
+) *AuthController {
 	return &AuthController{
-		authService: service.NewAuthService(),
+		authService: service.NewAuthService(trailDbSvc),
 	}
 }
 

+ 4 - 1
src/presentation/api/router.go

@@ -15,17 +15,20 @@ type Router struct {
 	baseRoute       *echo.Group
 	transientDbSvc  *internalDbInfra.TransientDatabaseService
 	persistentDbSvc *internalDbInfra.PersistentDatabaseService
+	trailDbSvc      *internalDbInfra.TrailDatabaseService
 }
 
 func NewRouter(
 	baseRoute *echo.Group,
 	transientDbSvc *internalDbInfra.TransientDatabaseService,
 	persistentDbSvc *internalDbInfra.PersistentDatabaseService,
+	trailDbSvc *internalDbInfra.TrailDatabaseService,
 ) *Router {
 	return &Router{
 		baseRoute:       baseRoute,
 		transientDbSvc:  transientDbSvc,
 		persistentDbSvc: persistentDbSvc,
+		trailDbSvc:      trailDbSvc,
 	}
 }
 
@@ -36,7 +39,7 @@ func (router Router) swaggerRoute() {
 
 func (router Router) authRoutes() {
 	authGroup := router.baseRoute.Group("/v1/auth")
-	authController := apiController.NewAuthController()
+	authController := apiController.NewAuthController(router.trailDbSvc)
 
 	authGroup.POST("/login/", authController.GenerateJwtWithCredentials)
 }

+ 2 - 1
src/presentation/cli/cli.go

@@ -36,8 +36,9 @@ func CliInit() {
 
 	transientDbSvc := cliInit.TransientDatabaseService()
 	persistentDbSvc := cliInit.PersistentDatabaseService()
+	trailDbSvc := cliInit.TrailDatabaseService()
 
-	router := NewRouter(transientDbSvc, persistentDbSvc)
+	router := NewRouter(transientDbSvc, persistentDbSvc, trailDbSvc)
 	router.RegisterRoutes()
 
 	RunRootCmd()

+ 5 - 2
src/presentation/cli/controller/authentication.go

@@ -1,6 +1,7 @@
 package cliController
 
 import (
+	internalDbInfra "github.com/speedianet/os/src/infra/internalDatabase"
 	cliHelper "github.com/speedianet/os/src/presentation/cli/helper"
 	"github.com/speedianet/os/src/presentation/service"
 	"github.com/spf13/cobra"
@@ -10,9 +11,11 @@ type AuthController struct {
 	authService *service.AuthService
 }
 
-func NewAuthController() *AuthController {
+func NewAuthController(
+	trailDbSvc *internalDbInfra.TrailDatabaseService,
+) *AuthController {
 	return &AuthController{
-		authService: service.NewAuthService(),
+		authService: service.NewAuthService(trailDbSvc),
 	}
 }
 

+ 10 - 3
src/presentation/cli/router.go

@@ -13,15 +13,18 @@ import (
 type Router struct {
 	transientDbSvc  *internalDbInfra.TransientDatabaseService
 	persistentDbSvc *internalDbInfra.PersistentDatabaseService
+	trailDbSvc      *internalDbInfra.TrailDatabaseService
 }
 
 func NewRouter(
 	transientDbSvc *internalDbInfra.TransientDatabaseService,
 	persistentDbSvc *internalDbInfra.PersistentDatabaseService,
+	trailDbSvc *internalDbInfra.TrailDatabaseService,
 ) *Router {
 	return &Router{
 		transientDbSvc:  transientDbSvc,
 		persistentDbSvc: persistentDbSvc,
+		trailDbSvc:      trailDbSvc,
 	}
 }
 
@@ -55,7 +58,7 @@ func (router Router) authenticationRoutes() {
 	}
 	rootCmd.AddCommand(authCmd)
 
-	authenticationController := cliController.AuthController{}
+	authenticationController := cliController.NewAuthController(router.trailDbSvc)
 	authCmd.AddCommand(authenticationController.Login())
 }
 
@@ -144,7 +147,9 @@ func (router *Router) scheduledTaskRoutes() {
 	}
 	rootCmd.AddCommand(scheduledTaskCmd)
 
-	scheduledTaskController := cliController.NewScheduledTaskController(router.persistentDbSvc)
+	scheduledTaskController := cliController.NewScheduledTaskController(
+		router.persistentDbSvc,
+	)
 	scheduledTaskCmd.AddCommand(scheduledTaskController.Read())
 	scheduledTaskCmd.AddCommand(scheduledTaskController.Update())
 }
@@ -154,7 +159,9 @@ func (router Router) serveRoutes() {
 		Use:   "serve",
 		Short: "Start Speedia OS HTTPS server (port 1618)",
 		Run: func(cmd *cobra.Command, args []string) {
-			presentation.HttpServerInit(router.persistentDbSvc, router.transientDbSvc)
+			presentation.HttpServerInit(
+				router.persistentDbSvc, router.transientDbSvc, router.trailDbSvc,
+			)
 		},
 	}
 

+ 2 - 1
src/presentation/http.go

@@ -26,10 +26,11 @@ func webServerSetup(
 func HttpServerInit(
 	persistentDbSvc *internalDbInfra.PersistentDatabaseService,
 	transientDbSvc *internalDbInfra.TransientDatabaseService,
+	trailDbSvc *internalDbInfra.TrailDatabaseService,
 ) {
 	e := echo.New()
 
-	api.ApiInit(e, persistentDbSvc, transientDbSvc)
+	api.ApiInit(e, persistentDbSvc, transientDbSvc, trailDbSvc)
 	ui.UiInit(e)
 
 	httpServer := http.Server{Addr: ":1618", Handler: e}

+ 17 - 3
src/presentation/service/authentication.go

@@ -5,15 +5,22 @@ import (
 	"github.com/speedianet/os/src/domain/useCase"
 	"github.com/speedianet/os/src/domain/valueObject"
 	accountInfra "github.com/speedianet/os/src/infra/account"
+	activityRecordInfra "github.com/speedianet/os/src/infra/activityRecord"
 	authInfra "github.com/speedianet/os/src/infra/auth"
+	internalDbInfra "github.com/speedianet/os/src/infra/internalDatabase"
 	serviceHelper "github.com/speedianet/os/src/presentation/service/helper"
 )
 
 type AuthService struct {
+	trailDbSvc *internalDbInfra.TrailDatabaseService
 }
 
-func NewAuthService() *AuthService {
-	return &AuthService{}
+func NewAuthService(
+	trailDbSvc *internalDbInfra.TrailDatabaseService,
+) *AuthService {
+	return &AuthService{
+		trailDbSvc: trailDbSvc,
+	}
 }
 
 func (service *AuthService) GenerateJwtWithCredentials(
@@ -45,9 +52,16 @@ func (service *AuthService) GenerateJwtWithCredentials(
 	authQueryRepo := authInfra.AuthQueryRepo{}
 	authCmdRepo := authInfra.AuthCmdRepo{}
 	accQueryRepo := accountInfra.AccQueryRepo{}
+	activityRecordQueryRepo := activityRecordInfra.NewActivityRecordQueryRepo(
+		service.trailDbSvc,
+	)
+	activityRecordCmdRepo := activityRecordInfra.NewActivityRecordCmdRepo(
+		service.trailDbSvc,
+	)
 
 	accessToken, err := useCase.GetSessionToken(
-		authQueryRepo, authCmdRepo, accQueryRepo, dto,
+		authQueryRepo, authCmdRepo, accQueryRepo, activityRecordQueryRepo,
+		activityRecordCmdRepo, dto,
 	)
 	if err != nil {
 		return NewServiceOutput(InfraError, err.Error())