195 lines
7.5 KiB
Go
195 lines
7.5 KiB
Go
package httpserver
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
_ "github.com/SamuelTariku/FortuneBet-Backend/docs"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"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.logger,
|
|
a.NotidicationStore,
|
|
a.validator,
|
|
a.walletSvc,
|
|
a.referralSvc,
|
|
a.virtualGameSvc,
|
|
a.userSvc,
|
|
a.transactionSvc,
|
|
a.ticketSvc,
|
|
a.betSvc,
|
|
a.authSvc,
|
|
a.JwtConfig,
|
|
a.branchSvc,
|
|
a.companySvc,
|
|
a.prematchSvc,
|
|
a.eventSvc,
|
|
)
|
|
|
|
a.fiber.Get("/", func(c *fiber.Ctx) error {
|
|
return c.JSON(fiber.Map{
|
|
"message": "Welcome to the FortuneBet API",
|
|
"version": "1.0dev2",
|
|
})
|
|
})
|
|
|
|
// Auth Routes
|
|
a.fiber.Post("/auth/login", h.LoginCustomer)
|
|
a.fiber.Post("/auth/refresh", h.RefreshToken)
|
|
a.fiber.Post("/auth/logout", a.authMiddleware, h.LogOutCustomer)
|
|
a.fiber.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")
|
|
})
|
|
|
|
// User Routes
|
|
a.fiber.Post("/user/resetPassword", h.ResetPassword)
|
|
a.fiber.Post("/user/sendResetCode", h.SendResetCode)
|
|
a.fiber.Post("/user/register", h.RegisterUser)
|
|
a.fiber.Post("/user/sendRegisterCode", h.SendRegisterCode)
|
|
a.fiber.Post("/user/checkPhoneEmailExist", h.CheckPhoneEmailExist)
|
|
a.fiber.Get("/user/profile", a.authMiddleware, h.UserProfile)
|
|
a.fiber.Get("/user/single/:id", a.authMiddleware, h.GetUserByID)
|
|
a.fiber.Delete("/user/delete/:id", a.authMiddleware, h.DeleteUser)
|
|
a.fiber.Post("/user/suspend", a.authMiddleware, h.UpdateUserSuspend)
|
|
|
|
a.fiber.Get("/user/wallet", a.authMiddleware, h.GetCustomerWallet)
|
|
a.fiber.Post("/user/search", a.authMiddleware, h.SearchUserByNameOrPhone)
|
|
|
|
// Referral Routes
|
|
a.fiber.Post("/referral/create", a.authMiddleware, h.CreateReferralCode)
|
|
a.fiber.Get("/referral/stats", a.authMiddleware, h.GetReferralStats)
|
|
a.fiber.Get("/referral/settings", h.GetReferralSettings)
|
|
a.fiber.Patch("/referral/settings", a.authMiddleware, h.UpdateReferralSettings)
|
|
|
|
a.fiber.Get("/cashiers", a.authMiddleware, h.GetAllCashiers)
|
|
a.fiber.Post("/cashiers", a.authMiddleware, h.CreateCashier)
|
|
a.fiber.Put("/cashiers/:id", a.authMiddleware, h.UpdateCashier)
|
|
|
|
a.fiber.Get("/admin", a.authMiddleware, h.GetAllAdmins)
|
|
a.fiber.Post("/admin", a.authMiddleware, h.CreateAdmin)
|
|
|
|
a.fiber.Get("/managers", a.authMiddleware, h.GetAllManagers)
|
|
a.fiber.Post("/managers", a.authMiddleware, h.CreateManager)
|
|
a.fiber.Put("/managers/:id", a.authMiddleware, h.UpdateManagers)
|
|
a.fiber.Get("/manager/:id/branch", a.authMiddleware, h.GetBranchByManagerID)
|
|
|
|
a.fiber.Get("/prematch/odds/:event_id", h.GetPrematchOdds)
|
|
a.fiber.Get("/prematch/odds", h.GetALLPrematchOdds)
|
|
a.fiber.Get("/prematch/odds/upcoming/:upcoming_id/market/:market_id", h.GetRawOddsByMarketID)
|
|
|
|
a.fiber.Get("/prematch/events/:id", h.GetUpcomingEventByID)
|
|
a.fiber.Get("/prematch/events", h.GetAllUpcomingEvents)
|
|
a.fiber.Get("/prematch/odds/upcoming/:upcoming_id", h.GetPrematchOddsByUpcomingID)
|
|
|
|
// Swagger
|
|
a.fiber.Get("/swagger/*", fiberSwagger.FiberWrapHandler())
|
|
|
|
// Branch
|
|
a.fiber.Post("/branch", a.authMiddleware, h.CreateBranch)
|
|
a.fiber.Get("/branch", a.authMiddleware, h.GetAllBranches)
|
|
a.fiber.Get("/branch/:id", a.authMiddleware, h.GetBranchByID)
|
|
a.fiber.Get("/branch/:id/bets", a.authMiddleware, h.GetBetByBranchID)
|
|
a.fiber.Put("/branch/:id", a.authMiddleware, h.UpdateBranch)
|
|
a.fiber.Delete("/branch/:id", a.authMiddleware, h.DeleteBranch)
|
|
a.fiber.Get("/search/branch", a.authMiddleware, h.SearchBranch)
|
|
// /branch/search
|
|
// branch/wallet
|
|
a.fiber.Get("/branch/:id/cashiers", a.authMiddleware, h.GetBranchCashiers)
|
|
|
|
// Branch Operation
|
|
a.fiber.Get("/supportedOperation", a.authMiddleware, h.GetAllSupportedOperations)
|
|
a.fiber.Post("/supportedOperation", a.authMiddleware, h.CreateSupportedOperation)
|
|
a.fiber.Post("/operation", a.authMiddleware, h.CreateBranchOperation)
|
|
a.fiber.Get("/branch/:id/operation", a.authMiddleware, h.GetBranchOperations)
|
|
|
|
a.fiber.Delete("/branch/:id/operation/:opID", a.authMiddleware, h.DeleteBranchOperation)
|
|
|
|
// Company
|
|
a.fiber.Post("/company", a.authMiddleware, a.SuperAdminOnly, h.CreateCompany)
|
|
a.fiber.Get("/company", a.authMiddleware, a.SuperAdminOnly, h.GetAllCompanies)
|
|
a.fiber.Get("/company/:id", a.authMiddleware, a.SuperAdminOnly, h.GetCompanyByID)
|
|
a.fiber.Put("/company/:id", a.authMiddleware, a.SuperAdminOnly, h.UpdateCompany)
|
|
a.fiber.Delete("/company/:id", a.authMiddleware, a.SuperAdminOnly, h.DeleteCompany)
|
|
a.fiber.Get("/company/:id/branch", a.authMiddleware, h.GetBranchByCompanyID)
|
|
a.fiber.Get("/search/company", a.authMiddleware, h.SearchCompany)
|
|
|
|
// Ticket Routes
|
|
a.fiber.Post("/ticket", h.CreateTicket)
|
|
a.fiber.Get("/ticket", h.GetAllTickets)
|
|
a.fiber.Get("/ticket/:id", h.GetTicketByID)
|
|
|
|
// Bet Routes
|
|
a.fiber.Post("/bet", a.authMiddleware, h.CreateBet)
|
|
a.fiber.Get("/bet", a.authMiddleware, h.GetAllBet)
|
|
a.fiber.Get("/bet/:id", h.GetBetByID)
|
|
a.fiber.Get("/bet/cashout/:id", a.authMiddleware, h.GetBetByCashoutID)
|
|
a.fiber.Patch("/bet/:id", a.authMiddleware, h.UpdateCashOut)
|
|
a.fiber.Delete("/bet/:id", a.authMiddleware, h.DeleteBet)
|
|
|
|
a.fiber.Post("/random/bet", a.authMiddleware, h.RandomBet)
|
|
|
|
// Wallet
|
|
a.fiber.Get("/wallet", h.GetAllWallets)
|
|
a.fiber.Get("/wallet/:id", h.GetWalletByID)
|
|
a.fiber.Put("/wallet/:id", h.UpdateWalletActive)
|
|
a.fiber.Get("/branchWallet", a.authMiddleware, h.GetAllBranchWallets)
|
|
|
|
// Transfer
|
|
// /transfer/wallet - transfer from one wallet to another wallet
|
|
a.fiber.Post("/transfer/wallet/:id", a.authMiddleware, h.TransferToWallet)
|
|
a.fiber.Get("/transfer/wallet/:id", a.authMiddleware, h.GetTransfersByWallet)
|
|
a.fiber.Post("/transfer/refill/:id", a.authMiddleware, h.RefillWallet)
|
|
|
|
// Transactions /transactions
|
|
a.fiber.Post("/transaction", a.authMiddleware, h.CreateTransaction)
|
|
a.fiber.Get("/transaction", a.authMiddleware, h.GetAllTransactions)
|
|
a.fiber.Get("/transaction/:id", a.authMiddleware, h.GetTransactionByID)
|
|
a.fiber.Put("/transaction/:id", a.authMiddleware, h.UpdateTransactionVerified)
|
|
|
|
// Notification Routes
|
|
a.fiber.Get("/ws/connect", a.WebsocketAuthMiddleware, h.ConnectSocket)
|
|
a.fiber.Get("/notifications", a.authMiddleware, h.GetNotifications)
|
|
a.fiber.Post("/notifications/mark-as-read", h.MarkNotificationAsRead)
|
|
a.fiber.Post("/notifications/create", h.CreateAndSendNotification)
|
|
|
|
// Virtual Game Routes
|
|
a.fiber.Post("/virtual-game/launch", a.authMiddleware, h.LaunchVirtualGame)
|
|
a.fiber.Post("/virtual-game/callback", h.HandleVirtualGameCallback)
|
|
|
|
}
|
|
|
|
///user/profile get
|
|
// @Router /user/resetPassword [post]
|
|
// @Router /user/sendResetCode [post]
|
|
// @Router /user/register [post]
|
|
// @Router /user/sendRegisterCode [post]
|
|
// @Router /user/checkPhoneEmailExist [post]
|