Yimaru-BackEnd/internal/web_server/app.go

139 lines
4.2 KiB
Go

package httpserver
import (
"Yimaru-Backend/internal/config"
"Yimaru-Backend/internal/services/arifpay"
"Yimaru-Backend/internal/services/authentication"
notificationservice "Yimaru-Backend/internal/services/notification"
"Yimaru-Backend/internal/services/recommendation"
referralservice "Yimaru-Backend/internal/services/referal"
"Yimaru-Backend/internal/services/settings"
"Yimaru-Backend/internal/services/transaction"
"Yimaru-Backend/internal/services/user"
jwtutil "Yimaru-Backend/internal/web_server/jwt"
customvalidator "Yimaru-Backend/internal/web_server/validator"
"fmt"
"log/slog"
"go.uber.org/zap"
"github.com/bytedance/sonic"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
type App struct {
// directDepositSvc *directdeposit.Service
// telebirrSvc *telebirr.TelebirrService
arifpaySvc *arifpay.ArifpayService
// santimpaySvc *santimpay.SantimPayService
// issueReportingSvc *issuereporting.Service
// instSvc *institutions.Service
// currSvc *currency.Service
fiber *fiber.App
recommendationSvc recommendation.RecommendationService
cfg *config.Config
logger *slog.Logger
NotidicationStore *notificationservice.Service
referralSvc *referralservice.Service
// raffleSvc *raffle.Service
// bonusSvc *bonus.Service
port int
settingSvc *settings.Service
authSvc *authentication.Service
userSvc *user.Service
// chapaSvc *chapa.Service
transactionSvc *transaction.Service
// branchSvc *branch.Service
// companySvc *company.Service
validator *customvalidator.CustomValidator
JwtConfig jwtutil.JwtConfig
Logger *slog.Logger
// statSvc *stats.Service
mongoLoggerSvc *zap.Logger
}
func NewApp(
// directDepositSvc *directdeposit.Service,
// telebirrSvc *telebirr.TelebirrService,
arifpaySvc *arifpay.ArifpayService,
// santimpaySvc *santimpay.SantimPayService,
// issueReportingSvc *issuereporting.Service,
// instSvc *institutions.Service,
// currSvc *currency.Service,
port int, validator *customvalidator.CustomValidator,
settingSvc *settings.Service,
authSvc *authentication.Service,
logger *slog.Logger,
JwtConfig jwtutil.JwtConfig,
userSvc *user.Service,
// chapaSvc *chapa.Service,
transactionSvc *transaction.Service,
// branchSvc *branch.Service,
// companySvc *company.Service,
notidicationStore *notificationservice.Service,
referralSvc *referralservice.Service,
// raffleSvc *raffle.Service,
// bonusSvc *bonus.Service,
recommendationSvc recommendation.RecommendationService,
// statSvc *stats.Service,
cfg *config.Config,
mongoLoggerSvc *zap.Logger,
) *App {
app := fiber.New(fiber.Config{
CaseSensitive: true,
DisableHeaderNormalizing: true,
JSONEncoder: sonic.Marshal,
JSONDecoder: sonic.Unmarshal,
})
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowMethods: "GET,POST,PUT,PATCH,DELETE,OPTIONS",
AllowHeaders: "Content-Type,Authorization,platform",
// AllowCredentials: true,
}))
app.Static("/static", "./static")
s := &App{
// directDepositSvc: directDepositSvc,
// telebirrSvc: telebirrSvc,
arifpaySvc: arifpaySvc,
// santimpaySvc: santimpaySvc,
// issueReportingSvc: issueReportingSvc,
// instSvc: instSvc,
// currSvc: currSvc,
fiber: app,
port: port,
settingSvc: settingSvc,
authSvc: authSvc,
validator: validator,
logger: logger,
JwtConfig: JwtConfig,
userSvc: userSvc,
// ticketSvc: ticketSvc,
// chapaSvc: chapaSvc,
transactionSvc: transactionSvc,
// branchSvc: branchSvc,
// companySvc: companySvc,
NotidicationStore: notidicationStore,
referralSvc: referralSvc,
// raffleSvc: raffleSvc,
// bonusSvc: bonusSvc,
Logger: logger,
recommendationSvc: recommendationSvc,
// statSvc: statSvc,
cfg: cfg,
mongoLoggerSvc: mongoLoggerSvc,
}
s.initAppRoutes()
return s
}
func (a *App) Run() error {
return a.fiber.Listen(fmt.Sprintf(":%d", a.port))
}