80 lines
3.0 KiB
Go
80 lines
3.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/odds"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/response"
|
|
"log/slog"
|
|
)
|
|
|
|
// GetPrematchOdds godoc
|
|
// @Summary Retrieve prematch odds for an event
|
|
// @Description Retrieve prematch odds for a specific event by event ID
|
|
// @Tags prematch
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param event_id path string true "Event ID"
|
|
// @Success 200 {array} domain.Odd
|
|
// @Failure 400 {object} response.APIResponse
|
|
// @Failure 500 {object} response.APIResponse
|
|
// @Router /prematch/odds/{event_id} [get]
|
|
func GetPrematchOdds(logger *slog.Logger, prematchSvc *odds.ServiceImpl) fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
eventID := c.Params("event_id")
|
|
if eventID == "" {
|
|
return response.WriteJSON(c, fiber.StatusBadRequest, "Missing event_id", nil, nil)
|
|
}
|
|
|
|
odds, err := prematchSvc.GetPrematchOdds(c.Context(), eventID)
|
|
if err != nil {
|
|
return response.WriteJSON(c, fiber.StatusInternalServerError, "Failed to retrieve odds", nil, nil)
|
|
}
|
|
|
|
return response.WriteJSON(c, fiber.StatusOK, "Prematch odds retrieved successfully", odds, nil)
|
|
}
|
|
}
|
|
//GetALLPrematchOdds
|
|
// @Summary Retrieve all prematch odds
|
|
// @Description Retrieve all prematch odds from the database
|
|
// @Tags prematch
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} domain.Odd
|
|
// @Failure 500 {object} response.APIResponse
|
|
// @Router /prematch/odds [get]
|
|
func GetALLPrematchOdds(logger *slog.Logger, prematchSvc *odds.ServiceImpl) fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
odds, err := prematchSvc.GetALLPrematchOdds(c.Context())
|
|
if err != nil {
|
|
return response.WriteJSON(c, fiber.StatusInternalServerError, "Failed to retrieve all prematch odds", nil, nil)
|
|
}
|
|
|
|
return response.WriteJSON(c, fiber.StatusOK, "All prematch odds retrieved successfully", odds, nil)
|
|
}
|
|
}
|
|
// GetRawOddsByID
|
|
// @Summary Retrieve raw odds by ID
|
|
// @Description Retrieve raw odds by raw odds ID
|
|
// @Tags prematch
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param raw_odds_id path string true "Raw Odds ID"
|
|
// @Success 200 {object} domain.RawOddsByID
|
|
// @Failure 400 {object} response.APIResponse
|
|
// @Failure 500 {object} response.APIResponse
|
|
// @Router /prematch/odds/raw/{raw_odds_id} [get]
|
|
func GetRawOddsByID(logger *slog.Logger, prematchSvc *odds.ServiceImpl) fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
rawOddsID := c.Params("raw_odds_id")
|
|
if rawOddsID == "" {
|
|
return response.WriteJSON(c, fiber.StatusBadRequest, "Missing raw_odds_id", nil, nil)
|
|
}
|
|
|
|
rawOdds, err := prematchSvc.GetRawOddsByID(c.Context(), rawOddsID)
|
|
if err != nil {
|
|
return response.WriteJSON(c, fiber.StatusInternalServerError, "Failed to retrieve raw odds", nil, nil)
|
|
}
|
|
|
|
return response.WriteJSON(c, fiber.StatusOK, "Raw odds retrieved successfully", rawOdds, nil)
|
|
}
|
|
} |