111 lines
3.6 KiB
Go
111 lines
3.6 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.userSvc,
|
|
a.transactionSvc,
|
|
a.ticketSvc,
|
|
a.betSvc,
|
|
a.authSvc,
|
|
a.JwtConfig,
|
|
)
|
|
|
|
// Auth Routes
|
|
a.fiber.Post("/auth/login", h.LoginCustomer)
|
|
a.fiber.Post("/auth/refresh", a.authMiddleware, 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)
|
|
|
|
// Wallet Routes
|
|
a.fiber.Get("/user/wallet", a.authMiddleware, h.GetCustomerWallet)
|
|
a.fiber.Get("/wallet", h.GetAllWallets)
|
|
a.fiber.Get("/wallet/:id", h.GetWalletByID)
|
|
a.fiber.Patch("/wallet/:id", h.UpdateWalletActive)
|
|
|
|
// Referral Routes
|
|
a.fiber.Post("/referral/create", a.authMiddleware, h.CreateReferral)
|
|
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)
|
|
|
|
// Swagger
|
|
a.fiber.Get("/swagger/*", fiberSwagger.FiberWrapHandler())
|
|
|
|
// 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", h.CreateBet)
|
|
a.fiber.Get("/bet", h.GetAllBet)
|
|
a.fiber.Get("/bet/:id", h.GetBetByID)
|
|
a.fiber.Patch("/bet/:id", h.UpdateCashOut)
|
|
a.fiber.Delete("/bet/:id", h.DeleteBet)
|
|
|
|
// Transaction Routes
|
|
a.fiber.Post("/transaction", h.CreateTransaction)
|
|
a.fiber.Get("/transaction", h.GetAllTransactions)
|
|
a.fiber.Get("/transaction/:id", h.GetTransactionByID)
|
|
a.fiber.Patch("/transaction/:id", h.UpdateTransactionVerified)
|
|
|
|
// Notification Routes
|
|
a.fiber.Get("/notifications/ws/connect/:recipientID", h.ConnectSocket)
|
|
a.fiber.Post("/notifications/mark-as-read", h.MarkNotificationAsRead)
|
|
a.fiber.Post("/notifications/create", h.CreateAndSendNotification)
|
|
}
|
|
|
|
// @Router /user/resetPassword [post]
|
|
// @Router /user/sendResetCode [post]
|
|
// @Router /user/register [post]
|
|
// @Router /user/sendRegisterCode [post]
|
|
// @Router /user/checkPhoneEmailExist [post]
|