319 lines
10 KiB
Go
319 lines
10 KiB
Go
package handlers
|
|
|
|
import (
|
|
"log"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// GetAllSports godoc
|
|
// @Summary Get all sports
|
|
// @Description Fetches all sports stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulseSport}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/sports [get]
|
|
func (h *Handler) GetAllSports(c *fiber.Ctx) error {
|
|
// Call service
|
|
sports, err := h.enetPulseSvc.GetAllSports(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllSports error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch sports",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "Sports fetched successfully",
|
|
Data: sports,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetAllTournamentTemplates godoc
|
|
// @Summary Get all tournament templates
|
|
// @Description Fetches all tournament templates stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulseTournamentTemplate}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/tournament-templates [get]
|
|
func (h *Handler) GetAllTournamentTemplates(c *fiber.Ctx) error {
|
|
// Call service
|
|
templates, err := h.enetPulseSvc.GetAllTournamentTemplates(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllTournamentTemplates error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch tournament templates",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "Tournament templates fetched successfully",
|
|
Data: templates,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetAllTournaments godoc
|
|
// @Summary Get all tournaments
|
|
// @Description Fetches all tournaments stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulseTournament}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/tournaments [get]
|
|
func (h *Handler) GetAllTournaments(c *fiber.Ctx) error {
|
|
// Call service
|
|
tournaments, err := h.enetPulseSvc.GetAllTournaments(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllTournaments error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch tournaments",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "Tournaments fetched successfully",
|
|
Data: tournaments,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetAllTournamentStages godoc
|
|
// @Summary Get all tournament stages
|
|
// @Description Fetches all tournament stages stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulseTournamentStage}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/tournament-stages [get]
|
|
func (h *Handler) GetAllTournamentStages(c *fiber.Ctx) error {
|
|
// Call service
|
|
stages, err := h.enetPulseSvc.GetAllTournamentStages(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllTournamentStages error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch tournament stages",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "Tournament stages fetched successfully",
|
|
Data: stages,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetFixturesByDate godoc
|
|
// @Summary Get all stored fixtures
|
|
// @Description Fetches all fixtures stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulseFixture}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/fixtures [get]
|
|
func (h *Handler) GetFixturesByDate(c *fiber.Ctx) error {
|
|
// Call service to get all fixtures from DB
|
|
fixtures, err := h.enetPulseSvc.GetAllFixtures(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllFixtures error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch fixtures from database",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "Fixtures fetched successfully",
|
|
Data: fixtures,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetAllResults godoc
|
|
// @Summary Get all results
|
|
// @Description Fetches all EnetPulse match results stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulseResult}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/results [get]
|
|
func (h *Handler) GetAllResults(c *fiber.Ctx) error {
|
|
// Call service
|
|
results, err := h.enetPulseSvc.GetAllResults(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllResults error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch EnetPulse results",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "EnetPulse results fetched successfully",
|
|
Data: results,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetAllPreodds godoc
|
|
// @Summary Get all preodds
|
|
// @Description Fetches all EnetPulse pre-match odds stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulsePreodds}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/preodds [get]
|
|
func (h *Handler) GetAllPreodds(c *fiber.Ctx) error {
|
|
// Call service
|
|
preodds, err := h.enetPulseSvc.GetAllPreodds(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllPreodds error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch EnetPulse preodds",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "EnetPulse preodds fetched successfully",
|
|
Data: preodds,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetAllBettingOffers godoc
|
|
// @Summary Get all betting offers
|
|
// @Description Fetches all EnetPulse preodds betting offers stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulsePreoddsBettingOffer}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/betting-offers [get]
|
|
func (h *Handler) GetAllBettingOffers(c *fiber.Ctx) error {
|
|
// Call service
|
|
offers, err := h.enetPulseSvc.GetAllBettingOffers(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllBettingOffers error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch EnetPulse betting offers",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "EnetPulse betting offers fetched successfully",
|
|
Data: offers,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetAllPreoddsWithBettingOffers godoc
|
|
// @Summary Get all preodds with betting offers
|
|
// @Description Fetches all EnetPulse pre-match odds along with their associated betting offers stored in the database
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulsePreodds}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/preodds-with-offers [get]
|
|
func (h *Handler) GetAllPreoddsWithBettingOffers(c *fiber.Ctx) error {
|
|
// Call service
|
|
preodds, err := h.enetPulseSvc.GetAllPreoddsWithBettingOffers(c.Context())
|
|
if err != nil {
|
|
log.Println("GetAllPreoddsWithBettingOffers error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch EnetPulse preodds with betting offers",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "EnetPulse preodds with betting offers fetched successfully",
|
|
Data: preodds,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// GetFixturesWithPreodds godoc
|
|
// @Summary Get fixtures with preodds
|
|
// @Description Fetches all EnetPulse fixtures along with their associated pre-match odds
|
|
// @Tags EnetPulse
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response{data=[]domain.EnetpulseFixtureWithPreodds}
|
|
// @Failure 502 {object} domain.ErrorResponse
|
|
// @Router /api/v1/enetpulse/fixtures/preodds [get]
|
|
func (h *Handler) GetFixturesWithPreodds(c *fiber.Ctx) error {
|
|
// Call service
|
|
fixtures, err := h.enetPulseSvc.GetFixturesWithPreodds(c.Context())
|
|
if err != nil {
|
|
log.Println("GetFixturesWithPreodds error:", err)
|
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
|
Message: "Failed to fetch EnetPulse fixtures with preodds",
|
|
Error: err.Error(),
|
|
})
|
|
}
|
|
|
|
// Return success response
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "EnetPulse fixtures with preodds fetched successfully",
|
|
Data: fixtures,
|
|
StatusCode: fiber.StatusOK,
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
// Helper: parse comma-separated string into []int
|
|
func ParseIntSlice(input string) []int {
|
|
if input == "" {
|
|
return nil
|
|
}
|
|
parts := strings.Split(input, ",")
|
|
result := make([]int, 0, len(parts))
|
|
for _, p := range parts {
|
|
if n, err := strconv.Atoi(strings.TrimSpace(p)); err == nil {
|
|
result = append(result, n)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
// Helper: convert []int to []int64
|
|
func IntSliceToInt64Slice(input []int) []int64 {
|
|
if input == nil {
|
|
return nil
|
|
}
|
|
result := make([]int64, len(input))
|
|
for i, v := range input {
|
|
result[i] = int64(v)
|
|
}
|
|
return result
|
|
}
|