package httpserver import ( "fmt" "log/slog" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/authentication" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/odds" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/bet" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/branch" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/ticket" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/transaction" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/user" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/wallet" jwtutil "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/jwt" customvalidator "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/validator" notificationservice "github.com/SamuelTariku/FortuneBet-Backend/internal/services/notfication" "github.com/bytedance/sonic" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" ) type App struct { fiber *fiber.App logger *slog.Logger NotidicationStore notificationservice.NotificationStore port int authSvc *authentication.Service userSvc *user.Service ticketSvc *ticket.Service betSvc *bet.Service walletSvc *wallet.Service transactionSvc *transaction.Service branchSvc *branch.Service validator *customvalidator.CustomValidator JwtConfig jwtutil.JwtConfig Logger *slog.Logger prematchSvc *odds.ServiceImpl } func NewApp( port int, validator *customvalidator.CustomValidator, authSvc *authentication.Service, logger *slog.Logger, JwtConfig jwtutil.JwtConfig, userSvc *user.Service, ticketSvc *ticket.Service, betSvc *bet.Service, walletSvc *wallet.Service, transactionSvc *transaction.Service, branchSvc *branch.Service, notidicationStore notificationservice.NotificationStore, prematchSvc *odds.ServiceImpl, ) *App { app := fiber.New(fiber.Config{ CaseSensitive: true, DisableHeaderNormalizing: true, JSONEncoder: sonic.Marshal, JSONDecoder: sonic.Unmarshal, }) app.Use(cors.New(cors.Config{ AllowOrigins: "http://localhost:5173", // Specify your frontend's origin AllowMethods: "GET,POST,PUT,DELETE", // Specify the allowed HTTP methods AllowHeaders: "Content-Type,Authorization", // Specify the allowed headers })) s := &App{ fiber: app, port: port, authSvc: authSvc, validator: validator, logger: logger, JwtConfig: JwtConfig, userSvc: userSvc, ticketSvc: ticketSvc, betSvc: betSvc, walletSvc: walletSvc, transactionSvc: transactionSvc, branchSvc: branchSvc, NotidicationStore: notidicationStore, Logger: logger, prematchSvc: prematchSvc, } s.initAppRoutes() return s } func (a *App) Run() error { return a.fiber.Listen(fmt.Sprintf(":%d", a.port)) }