This commit is contained in:
Aditya Siregar
2025-09-18 02:01:50 +07:00
parent 259b8a11b5
commit f64fec1fe2
10 changed files with 743 additions and 247 deletions
+15 -4
View File
@@ -42,7 +42,7 @@ func (a *App) Initialize(cfg *config.Config) error {
processors := a.initProcessors(cfg, repos)
services := a.initServices(processors, repos, cfg)
validators := a.initValidators()
middleware := a.initMiddleware(services)
middleware := a.initMiddleware(services, cfg)
healthHandler := handler.NewHealthHandler()
a.router = router.NewRouter(
@@ -102,6 +102,8 @@ func (a *App) Initialize(cfg *config.Config) error {
validators.campaignValidator,
services.customerAuthService,
validators.customerAuthValidator,
services.customerPointsService,
middleware.customerAuthMiddleware,
)
return nil
@@ -185,6 +187,7 @@ type repositories struct {
rewardRepo repository.RewardRepository
campaignRepo repository.CampaignRepository
customerAuthRepo repository.CustomerAuthRepository
customerPointsRepo repository.CustomerPointsRepository
otpRepo repository.OtpRepository
txManager *repository.TxManager
}
@@ -229,6 +232,7 @@ func (a *App) initRepositories() *repositories {
rewardRepo: repository.NewRewardRepository(a.db),
campaignRepo: repository.NewCampaignRepository(a.db),
customerAuthRepo: repository.NewCustomerAuthRepository(a.db),
customerPointsRepo: repository.NewCustomerPointsRepository(a.db),
otpRepo: repository.NewOtpRepository(a.db),
txManager: repository.NewTxManager(a.db),
}
@@ -269,6 +273,7 @@ type processors struct {
rewardProcessor processor.RewardProcessor
campaignProcessor processor.CampaignProcessor
customerAuthProcessor processor.CustomerAuthProcessor
customerPointsProcessor *processor.CustomerPointsProcessor
otpProcessor processor.OtpProcessor
fileClient processor.FileClient
inventoryMovementService service.InventoryMovementService
@@ -315,6 +320,7 @@ func (a *App) initProcessors(cfg *config.Config, repos *repositories) *processor
rewardProcessor: processor.NewRewardProcessor(repos.rewardRepo),
campaignProcessor: processor.NewCampaignProcessor(repos.campaignRepo),
customerAuthProcessor: processor.NewCustomerAuthProcessor(repos.customerAuthRepo, otpProcessor, repos.otpRepo, cfg.GetCustomerJWTSecret(), cfg.GetCustomerJWTExpiresTTL()),
customerPointsProcessor: processor.NewCustomerPointsProcessor(repos.customerPointsRepo),
otpProcessor: otpProcessor,
fileClient: fileClient,
inventoryMovementService: inventoryMovementService,
@@ -352,6 +358,7 @@ type services struct {
rewardService service.RewardService
campaignService service.CampaignService
customerAuthService service.CustomerAuthService
customerPointsService service.CustomerPointsService
}
func (a *App) initServices(processors *processors, repos *repositories, cfg *config.Config) *services {
@@ -386,6 +393,7 @@ func (a *App) initServices(processors *processors, repos *repositories, cfg *con
rewardService := service.NewRewardService(processors.rewardProcessor)
campaignService := service.NewCampaignService(processors.campaignProcessor)
customerAuthService := service.NewCustomerAuthService(processors.customerAuthProcessor)
customerPointsService := service.NewCustomerPointsService(processors.customerPointsProcessor)
// Update order service with order ingredient transaction service
orderService = service.NewOrderServiceImpl(processors.orderProcessor, repos.tableRepo, orderIngredientTransactionService, processors.orderIngredientTransactionProcessor, *repos.productRecipeRepo, repos.txManager)
@@ -421,16 +429,19 @@ func (a *App) initServices(processors *processors, repos *repositories, cfg *con
rewardService: rewardService,
campaignService: campaignService,
customerAuthService: customerAuthService,
customerPointsService: customerPointsService,
}
}
type middlewares struct {
authMiddleware *middleware.AuthMiddleware
authMiddleware *middleware.AuthMiddleware
customerAuthMiddleware *middleware.CustomerAuthMiddleware
}
func (a *App) initMiddleware(services *services) *middlewares {
func (a *App) initMiddleware(services *services, cfg *config.Config) *middlewares {
return &middlewares{
authMiddleware: middleware.NewAuthMiddleware(services.authService),
authMiddleware: middleware.NewAuthMiddleware(services.authService),
customerAuthMiddleware: middleware.NewCustomerAuthMiddleware(cfg.GetCustomerJWTSecret()),
}
}