320 lines
14 KiB
Go
320 lines
14 KiB
Go
package httpserver
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
_ "github.com/SamuelTariku/FortuneBet-Backend/docs"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
|
|
// "github.com/SamuelTariku/FortuneBet-Backend/internal/logger/mongoLogger"
|
|
|
|
// "github.com/SamuelTariku/FortuneBet-Backend/internal/services/wallet/monitor"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/handlers"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
fiberSwagger "github.com/swaggo/fiber-swagger"
|
|
)
|
|
|
|
func (a *App) initAppRoutes() {
|
|
h := handlers.New(
|
|
a.arifpaySvc,
|
|
a.issueReportingSvc,
|
|
a.instSvc,
|
|
a.currSvc,
|
|
a.logger,
|
|
a.settingSvc,
|
|
a.NotidicationStore,
|
|
a.validator,
|
|
a.reportSvc,
|
|
a.chapaSvc,
|
|
a.walletSvc,
|
|
a.referralSvc,
|
|
a.bonusSvc,
|
|
a.virtualGameSvc,
|
|
a.aleaVirtualGameService,
|
|
a.veliVirtualGameService,
|
|
a.recommendationSvc,
|
|
a.userSvc,
|
|
a.transactionSvc,
|
|
a.ticketSvc,
|
|
a.betSvc,
|
|
a.authSvc,
|
|
a.JwtConfig,
|
|
a.branchSvc,
|
|
a.companySvc,
|
|
a.prematchSvc,
|
|
a.eventSvc,
|
|
a.leagueSvc,
|
|
*a.resultSvc,
|
|
a.cfg,
|
|
a.mongoLoggerSvc,
|
|
)
|
|
|
|
a.fiber.Get("/", func(c *fiber.Ctx) error {
|
|
return c.JSON(fiber.Map{
|
|
"message": "Welcome to the FortuneBet API",
|
|
"version": "1.0dev11",
|
|
})
|
|
})
|
|
|
|
// Swagger
|
|
a.fiber.Get("/swagger/*", fiberSwagger.FiberWrapHandler())
|
|
|
|
groupV1 := a.fiber.Group("/api/v1")
|
|
groupV1.Get("/", func(c *fiber.Ctx) error {
|
|
return c.JSON(fiber.Map{
|
|
"message": "FortuneBet API V1 pre-alpha",
|
|
"version": "1.0dev11",
|
|
})
|
|
})
|
|
|
|
// Auth Routes
|
|
groupV1.Post("/auth/customer-login", h.LoginCustomer)
|
|
groupV1.Post("/auth/admin-login", h.LoginAdmin)
|
|
groupV1.Post("/auth/refresh", h.RefreshToken)
|
|
groupV1.Post("/auth/logout", a.authMiddleware, h.LogOutCustomer)
|
|
groupV1.Get("/auth/test", a.authMiddleware, func(c *fiber.Ctx) error {
|
|
userID, ok := c.Locals("user_id").(int64)
|
|
if !ok {
|
|
return fiber.NewError(fiber.StatusUnauthorized, "Invalid user ID")
|
|
}
|
|
role, ok := c.Locals("role").(domain.Role)
|
|
if !ok {
|
|
return fiber.NewError(fiber.StatusUnauthorized, "Invalid role")
|
|
}
|
|
refreshToken, ok := c.Locals("refresh_token").(string)
|
|
if !ok {
|
|
return fiber.NewError(fiber.StatusUnauthorized, "Invalid refresh token")
|
|
}
|
|
companyID, err := strconv.ParseInt(c.Get("company_id"), 10, 64)
|
|
if err != nil {
|
|
return fiber.NewError(fiber.StatusBadRequest, "Invalid company_id")
|
|
}
|
|
|
|
a.logger.Info("User ID: " + strconv.FormatInt(userID, 10))
|
|
fmt.Printf("User ID: %d\n", userID)
|
|
a.logger.Info("Role: " + string(role))
|
|
a.logger.Info("Refresh Token: " + refreshToken)
|
|
a.logger.Info("Company ID: " + strconv.FormatInt(companyID, 10))
|
|
return c.SendString("Test endpoint")
|
|
})
|
|
|
|
//Arifpay
|
|
groupV1.Post("/arifpay/checkout", a.authMiddleware, h.CreateCheckoutSessionHandler)
|
|
groupV1.Post("/arifpay/b2c/transfer", a.authMiddleware, h.B2CTransferHandler)
|
|
groupV1.Post("/arifpay/transaction-id/verify-transaction", a.authMiddleware, h.ArifpayVerifyByTransactionIDHandler)
|
|
groupV1.Get("/arifpay/session-id/verify-transaction/:session_id", a.authMiddleware, h.ArifpayVerifyBySessionIDHandler)
|
|
|
|
// User Routes
|
|
groupV1.Post("/user/resetPassword", h.ResetPassword)
|
|
groupV1.Post("/user/sendResetCode", h.SendResetCode)
|
|
groupV1.Post("/user/register", h.RegisterUser)
|
|
groupV1.Post("/user/sendRegisterCode", h.SendRegisterCode)
|
|
groupV1.Post("/user/checkPhoneEmailExist", h.CheckPhoneEmailExist)
|
|
groupV1.Get("/user/customer-profile", a.authMiddleware, h.CustomerProfile)
|
|
groupV1.Get("/user/admin-profile", a.authMiddleware, h.AdminProfile)
|
|
groupV1.Get("/user/single/:id", a.authMiddleware, h.GetUserByID)
|
|
groupV1.Delete("/user/delete/:id", a.authMiddleware, h.DeleteUser)
|
|
groupV1.Post("/user/suspend", a.authMiddleware, h.UpdateUserSuspend)
|
|
groupV1.Get("/user/bets", a.authMiddleware, h.GetBetByUserID)
|
|
|
|
groupV1.Get("/user/wallet", a.authMiddleware, h.GetCustomerWallet)
|
|
groupV1.Post("/user/search", a.authMiddleware, h.SearchUserByNameOrPhone)
|
|
|
|
// Referral Routes
|
|
groupV1.Post("/referral/create", a.authMiddleware, h.CreateReferralCode)
|
|
groupV1.Get("/referral/stats", a.authMiddleware, h.GetReferralStats)
|
|
groupV1.Post("/referral/settings", a.authMiddleware, h.CreateReferralSettings)
|
|
groupV1.Get("/referral/settings", a.authMiddleware, h.GetReferralSettings)
|
|
groupV1.Patch("/referral/settings", a.authMiddleware, h.UpdateReferralSettings)
|
|
|
|
// Bonus Routes
|
|
groupV1.Get("/bonus", a.authMiddleware, h.GetBonusMultiplier)
|
|
groupV1.Post("/bonus/create", a.authMiddleware, h.CreateBonusMultiplier)
|
|
groupV1.Put("/bonus/update", a.authMiddleware, h.UpdateBonusMultiplier)
|
|
|
|
groupV1.Get("/cashiers", a.authMiddleware, h.GetAllCashiers)
|
|
groupV1.Get("/cashiers/:id", a.authMiddleware, h.GetCashierByID)
|
|
groupV1.Post("/cashiers", a.authMiddleware, h.CreateCashier)
|
|
groupV1.Put("/cashiers/:id", a.authMiddleware, h.UpdateCashier)
|
|
|
|
groupV1.Get("/customer", a.authMiddleware, a.SuperAdminOnly, h.GetAllCustomers)
|
|
groupV1.Get("/customer/:id", a.authMiddleware, a.SuperAdminOnly, h.GetCustomerByID)
|
|
groupV1.Put("/customer/:id", a.authMiddleware, a.SuperAdminOnly, h.UpdateCustomer)
|
|
|
|
groupV1.Get("/admin", a.authMiddleware, h.GetAllAdmins)
|
|
groupV1.Get("/admin/:id", a.authMiddleware, h.GetAdminByID)
|
|
groupV1.Post("/admin", a.authMiddleware, h.CreateAdmin)
|
|
groupV1.Put("/admin/:id", a.authMiddleware, h.UpdateAdmin)
|
|
|
|
groupV1.Get("/managers", a.authMiddleware, h.GetAllManagers)
|
|
groupV1.Get("/managers/:id", a.authMiddleware, h.GetManagerByID)
|
|
groupV1.Post("/managers", a.authMiddleware, h.CreateManager)
|
|
groupV1.Put("/managers/:id", a.authMiddleware, h.UpdateManagers)
|
|
groupV1.Get("/manager/:id/branch", a.authMiddleware, h.GetBranchByManagerID)
|
|
|
|
groupV1.Get("/odds", h.GetALLPrematchOdds)
|
|
groupV1.Get("/odds/upcoming/:upcoming_id", h.GetOddsByUpcomingID)
|
|
groupV1.Get("/odds/upcoming/:upcoming_id/market/:market_id", h.GetRawOddsByMarketID)
|
|
|
|
groupV1.Get("/events", h.GetAllUpcomingEvents)
|
|
groupV1.Get("/events/:id", h.GetUpcomingEventByID)
|
|
groupV1.Delete("/events/:id", a.authMiddleware, a.SuperAdminOnly, h.SetEventStatusToRemoved)
|
|
groupV1.Get("/top-leagues", h.GetTopLeagues)
|
|
groupV1.Put("/events/:id/featured", h.UpdateEventFeatured)
|
|
|
|
// Leagues
|
|
groupV1.Get("/leagues", h.GetAllLeagues)
|
|
groupV1.Put("/leagues/:id/set-active", h.SetLeagueActive)
|
|
groupV1.Put("/leagues/:id/featured", h.SetLeagueFeatured)
|
|
|
|
groupV1.Get("/result/:id", h.GetResultsByEventID)
|
|
|
|
// Branch
|
|
groupV1.Post("/branch", a.authMiddleware, h.CreateBranch)
|
|
groupV1.Get("/branch", a.authMiddleware, h.GetAllBranches)
|
|
groupV1.Get("/branch/:id", a.authMiddleware, h.GetBranchByID)
|
|
groupV1.Get("/branch/:id/bets", a.authMiddleware, h.GetBetByBranchID)
|
|
groupV1.Put("/branch/:id", a.authMiddleware, h.UpdateBranch)
|
|
groupV1.Put("/branch/:id/set-active", a.authMiddleware, h.UpdateBranchStatus)
|
|
groupV1.Put("/branch/:id/set-inactive", a.authMiddleware, h.UpdateBranchStatus)
|
|
groupV1.Delete("/branch/:id", a.authMiddleware, h.DeleteBranch)
|
|
|
|
groupV1.Get("/search/branch", a.authMiddleware, h.SearchBranch)
|
|
|
|
groupV1.Get("/branchLocation", a.authMiddleware, h.GetAllBranchLocations)
|
|
|
|
groupV1.Get("/branch/:id/cashiers", a.authMiddleware, h.GetBranchCashiers)
|
|
groupV1.Get("/branchCashier", a.authMiddleware, h.GetBranchForCashier)
|
|
|
|
// Branch Operation
|
|
groupV1.Get("/supportedOperation", a.authMiddleware, h.GetAllSupportedOperations)
|
|
groupV1.Post("/supportedOperation", a.authMiddleware, h.CreateSupportedOperation)
|
|
groupV1.Post("/operation", a.authMiddleware, h.CreateBranchOperation)
|
|
groupV1.Get("/branch/:id/operation", a.authMiddleware, h.GetBranchOperations)
|
|
|
|
groupV1.Delete("/branch/:id/operation/:opID", a.authMiddleware, h.DeleteBranchOperation)
|
|
|
|
// Company
|
|
groupV1.Post("/company", a.authMiddleware, a.SuperAdminOnly, h.CreateCompany)
|
|
groupV1.Get("/company", a.authMiddleware, a.SuperAdminOnly, h.GetAllCompanies)
|
|
groupV1.Get("/company/:id", a.authMiddleware, a.SuperAdminOnly, h.GetCompanyByID)
|
|
groupV1.Put("/company/:id", a.authMiddleware, a.SuperAdminOnly, h.UpdateCompany)
|
|
groupV1.Delete("/company/:id", a.authMiddleware, a.SuperAdminOnly, h.DeleteCompany)
|
|
groupV1.Get("/company/:id/branch", a.authMiddleware, h.GetBranchByCompanyID)
|
|
groupV1.Get("/search/company", a.authMiddleware, h.SearchCompany)
|
|
groupV1.Get("/admin-company", a.authMiddleware, h.GetCompanyForAdmin)
|
|
|
|
// Ticket Routes
|
|
groupV1.Post("/ticket", h.CreateTicket)
|
|
groupV1.Get("/ticket", h.GetAllTickets)
|
|
groupV1.Get("/ticket/:id", h.GetTicketByID)
|
|
|
|
// Bet Routes
|
|
groupV1.Post("/sport/bet", a.authMiddleware, h.CreateBet)
|
|
groupV1.Post("/sport/bet/fastcode", a.authMiddleware, h.CreateBetWithFastCode)
|
|
groupV1.Get("/sport/bet/fastcode/:fast_code", h.GetBetByFastCode)
|
|
groupV1.Get("/sport/bet", a.authMiddleware, h.GetAllBet)
|
|
groupV1.Get("/sport/bet/:id", h.GetBetByID)
|
|
groupV1.Patch("/sport/bet/:id", a.authMiddleware, h.UpdateCashOut)
|
|
groupV1.Delete("/sport/bet/:id", a.authMiddleware, h.DeleteBet)
|
|
|
|
groupV1.Post("/sport/random/bet", a.authMiddleware, h.RandomBet)
|
|
|
|
// Wallet
|
|
groupV1.Get("/wallet", h.GetAllWallets)
|
|
groupV1.Get("/wallet/:id", h.GetWalletByID)
|
|
groupV1.Put("/wallet/:id", h.UpdateWalletActive)
|
|
groupV1.Get("/branchWallet", a.authMiddleware, h.GetAllBranchWallets)
|
|
groupV1.Get("/customerWallet", a.authMiddleware, h.GetAllCustomerWallets)
|
|
groupV1.Get("/cashierWallet", a.authMiddleware, h.GetWalletForCashier)
|
|
|
|
// Transfer
|
|
// /transfer/wallet - transfer from one wallet to another wallet
|
|
groupV1.Post("/transfer/wallet/:id", a.authMiddleware, h.TransferToWallet)
|
|
groupV1.Get("/transfer/wallet/:id", a.authMiddleware, h.GetTransfersByWallet)
|
|
groupV1.Post("/transfer/refill/:id", a.authMiddleware, h.RefillWallet)
|
|
|
|
//Chapa Routes
|
|
groupV1.Post("/chapa/payments/webhook/verify", h.WebhookCallback)
|
|
groupV1.Get("/chapa/payments/manual/verify/:tx_ref", h.ManualVerifyTransaction)
|
|
groupV1.Post("/chapa/payments/deposit", a.authMiddleware, h.InitiateDeposit)
|
|
groupV1.Post("/chapa/payments/withdraw", a.authMiddleware, h.InitiateWithdrawal)
|
|
groupV1.Get("/chapa/banks", h.GetSupportedBanks)
|
|
|
|
// Currencies
|
|
groupV1.Get("/currencies", h.GetSupportedCurrencies)
|
|
groupV1.Get("/currencies/convert", h.ConvertCurrency)
|
|
|
|
//Report Routes
|
|
groupV1.Get("/reports/dashboard", a.authMiddleware, a.OnlyAdminAndAbove, h.GetDashboardReport)
|
|
groupV1.Get("/report-files/download/:filename", a.authMiddleware, a.OnlyAdminAndAbove, h.DownloadReportFile)
|
|
groupV1.Get("/report-files/list", a.authMiddleware, a.OnlyAdminAndAbove, h.ListReportFiles)
|
|
|
|
//Alea Play Virtual Game Routes
|
|
groupV1.Get("/alea-play/launch", a.authMiddleware, h.LaunchAleaGame)
|
|
groupV1.Post("/webhooks/alea-play", a.authMiddleware, h.HandleAleaCallback)
|
|
|
|
//Veli Virtual Game Routes
|
|
groupV1.Post("/veli/providers", h.GetProviders)
|
|
groupV1.Post("/veli/games-list", h.GetGamesByProvider)
|
|
groupV1.Post("/veli/start-game", a.authMiddleware, h.StartGame)
|
|
groupV1.Post("/veli/start-demo-game", a.authMiddleware, h.StartDemoGame)
|
|
a.fiber.Post("/balance", h.GetBalance)
|
|
groupV1.Post("/veli/gaming-activity", h.GetGamingActivity)
|
|
|
|
//mongoDB logs
|
|
groupV1.Get("/logs", a.authMiddleware, a.SuperAdminOnly, handlers.GetLogsHandler(context.Background()))
|
|
|
|
// Recommendation Routes
|
|
// group.Get("/virtual-games/recommendations/:userID", h.GetRecommendations)
|
|
|
|
// Transactions /shop/transactions
|
|
groupV1.Post("/shop/bet", a.authMiddleware, a.CompanyOnly, h.CreateShopBet)
|
|
groupV1.Get("/shop/bet", a.authMiddleware, a.CompanyOnly, h.GetAllShopBets)
|
|
groupV1.Get("/shop/bet/:id", a.authMiddleware, a.CompanyOnly, h.GetShopBetByBetID)
|
|
groupV1.Post("/shop/bet/:id/cashout", a.authMiddleware, a.CompanyOnly, h.CashoutBet)
|
|
groupV1.Post("/shop/bet/:id/generate", a.authMiddleware, a.CompanyOnly, h.CashoutBet)
|
|
groupV1.Get("/shop/cashout/:id", a.authMiddleware, a.CompanyOnly, h.GetShopBetByCashoutID)
|
|
groupV1.Post("/shop/cashout", a.authMiddleware, a.CompanyOnly, h.CashoutByCashoutID)
|
|
groupV1.Post("/shop/deposit", a.authMiddleware, a.CompanyOnly, h.DepositForCustomer)
|
|
// groupV1.Get("/shop/deposit", a.authMiddleware, a.CompanyOnly, h.DepositForCustomer)
|
|
groupV1.Get("/shop/transaction", a.authMiddleware, h.GetAllTransactions)
|
|
groupV1.Get("/shop/transaction/:id", a.authMiddleware, h.GetTransactionByID)
|
|
groupV1.Get("/shop/transaction/:id/bet", a.authMiddleware, h.GetShopBetByTransactionID)
|
|
groupV1.Put("/shop/transaction/:id", a.authMiddleware, h.UpdateTransactionVerified)
|
|
|
|
// Notification Routes
|
|
groupV1.Get("/ws/connect", a.WebsocketAuthMiddleware, h.ConnectSocket)
|
|
groupV1.Get("/notifications", a.authMiddleware, h.GetNotifications)
|
|
groupV1.Get("/notifications/all", a.authMiddleware, h.GetAllNotifications)
|
|
groupV1.Post("/notifications/mark-as-read", a.authMiddleware, h.MarkNotificationAsRead)
|
|
groupV1.Get("/notifications/unread", a.authMiddleware, h.CountUnreadNotifications)
|
|
groupV1.Post("/notifications/create", a.authMiddleware, h.CreateAndSendNotification)
|
|
|
|
// Virtual Game Routes
|
|
a.fiber.Post("/virtual-game/launch", a.authMiddleware, h.LaunchVirtualGame)
|
|
a.fiber.Post("/virtual-game/callback", h.HandleVirtualGameCallback)
|
|
a.fiber.Post("/playerInfo", h.HandlePlayerInfo)
|
|
a.fiber.Post("/bet", h.HandleBet)
|
|
a.fiber.Post("/win", h.HandleWin)
|
|
a.fiber.Post("/cancel", h.HandleCancel)
|
|
a.fiber.Post("/promoWin ", h.HandlePromoWin)
|
|
a.fiber.Post("/tournamentWin ", h.HandleTournamentWin)
|
|
a.fiber.Get("/popok/games", h.GetGameList)
|
|
a.fiber.Get("/popok/games/recommend", a.authMiddleware, h.RecommendGames)
|
|
groupV1.Post("/virtual-game/favorites", a.authMiddleware, h.AddFavorite)
|
|
groupV1.Delete("/virtual-game/favorites/:gameID", a.authMiddleware, h.RemoveFavorite)
|
|
groupV1.Get("/virtual-game/favorites", a.authMiddleware, h.ListFavorites)
|
|
|
|
//Issue Reporting Routes
|
|
groupV1.Post("/issues", a.authMiddleware, h.CreateIssue) //anyone who has logged can report a
|
|
groupV1.Get("/issues/customer/:customer_id", a.authMiddleware, a.OnlyAdminAndAbove, h.GetUserIssues)
|
|
groupV1.Get("/issues", a.authMiddleware, a.OnlyAdminAndAbove, h.GetAllIssues)
|
|
groupV1.Patch("/issues/:issue_id/status", a.authMiddleware, a.OnlyAdminAndAbove, h.UpdateIssueStatus)
|
|
groupV1.Delete("/issues/:issue_id", a.authMiddleware, a.OnlyAdminAndAbove, h.DeleteIssue)
|
|
}
|