147 lines
4.8 KiB
Go
147 lines
4.8 KiB
Go
package handlers
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/response"
|
|
"github.com/gofiber/fiber/v2"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// 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 /api/v1/odds [get]
|
|
func (h *Handler) GetALLPrematchOdds(c *fiber.Ctx) error {
|
|
|
|
odds, err := h.prematchSvc.GetALLPrematchOdds(c.Context())
|
|
if err != nil {
|
|
h.mongoLoggerSvc.Error("Failed to retrieve all prematch odds",
|
|
zap.Int("status_code", fiber.StatusInternalServerError),
|
|
zap.Error(err),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
|
}
|
|
|
|
return response.WriteJSON(c, fiber.StatusOK, "All prematch odds retrieved successfully", odds, nil)
|
|
|
|
}
|
|
|
|
// GetRawOddsByMarketID
|
|
// @Summary Retrieve raw odds by Market ID
|
|
// @Description Retrieve raw odds records using a Market ID
|
|
// @Tags prematch
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param upcoming_id path string true "Upcoming ID"
|
|
// @Param market_id path string true "Market ID"
|
|
// @Success 200 {array} domain.RawOddsByMarketID
|
|
// @Failure 400 {object} response.APIResponse
|
|
// @Failure 500 {object} response.APIResponse
|
|
// @Router /api/v1/odds/upcoming/{upcoming_id}/market/{market_id} [get]
|
|
func (h *Handler) GetRawOddsByMarketID(c *fiber.Ctx) error {
|
|
|
|
marketID := c.Params("market_id")
|
|
if marketID == "" {
|
|
h.mongoLoggerSvc.Info("Missing market_id",
|
|
zap.String("market_id", marketID),
|
|
zap.Int("status_code", fiber.StatusBadRequest),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusBadRequest, "Missing market_id")
|
|
}
|
|
|
|
upcomingID := c.Params("upcoming_id")
|
|
if upcomingID == "" {
|
|
h.mongoLoggerSvc.Info("Missing upcoming_id",
|
|
zap.String("upcoming", upcomingID),
|
|
zap.Int("status_code", fiber.StatusBadRequest),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusBadRequest, "Missing upcoming_id")
|
|
}
|
|
|
|
rawOdds, err := h.prematchSvc.GetRawOddsByMarketID(c.Context(), marketID, upcomingID)
|
|
if err != nil {
|
|
h.mongoLoggerSvc.Error("Failed to get raw odds by market ID",
|
|
zap.String("marketID", marketID),
|
|
zap.String("upcomingID", upcomingID),
|
|
zap.Int("status_code", fiber.StatusInternalServerError),
|
|
zap.Error(err),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
|
}
|
|
|
|
return response.WriteJSON(c, fiber.StatusOK, "Raw odds retrieved successfully", rawOdds, nil)
|
|
|
|
}
|
|
|
|
// @Summary Retrieve prematch odds by upcoming ID (FI)
|
|
// @Description Retrieve prematch odds by upcoming event ID (FI from Bet365) with optional pagination
|
|
// @Tags prematch
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param upcoming_id path string true "Upcoming Event ID (FI)"
|
|
// @Param limit query int false "Number of results to return (default: 10)"
|
|
// @Param offset query int false "Number of results to skip (default: 0)"
|
|
// @Success 200 {array} domain.Odd
|
|
// @Failure 400 {object} response.APIResponse
|
|
// @Failure 500 {object} response.APIResponse
|
|
// @Router /api/v1/odds/upcoming/{upcoming_id} [get]
|
|
func (h *Handler) GetOddsByUpcomingID(c *fiber.Ctx) error {
|
|
|
|
upcomingID := c.Params("upcoming_id")
|
|
if upcomingID == "" {
|
|
h.mongoLoggerSvc.Info("Missing upcoming_id",
|
|
zap.String("upcoming", upcomingID),
|
|
zap.Int("status_code", fiber.StatusBadRequest),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusBadRequest, "Missing upcoming_id")
|
|
}
|
|
|
|
limit, err := strconv.Atoi(c.Query("limit", "10")) // Default limit is 10
|
|
if err != nil || limit <= 0 {
|
|
h.mongoLoggerSvc.Info("Invalid limit value",
|
|
zap.Int("limit", limit),
|
|
zap.Int("status_code", fiber.StatusInternalServerError),
|
|
zap.Error(err),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusBadRequest, "Invalid limit value")
|
|
}
|
|
|
|
offset, err := strconv.Atoi(c.Query("offset", "0")) // Default offset is 0
|
|
if err != nil || offset < 0 {
|
|
h.mongoLoggerSvc.Info("Invalid offset value",
|
|
zap.Int("offset", offset),
|
|
zap.Int("status_code", fiber.StatusBadRequest),
|
|
zap.Error(err),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
}
|
|
|
|
odds, err := h.prematchSvc.GetPrematchOddsByUpcomingID(c.Context(), upcomingID)
|
|
if err != nil {
|
|
h.mongoLoggerSvc.Error("Failed to retrieve prematch odds",
|
|
zap.String("upcoming", upcomingID),
|
|
zap.Int("status_code", fiber.StatusInternalServerError),
|
|
zap.Error(err),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to retrieve prematch odds"+err.Error())
|
|
}
|
|
|
|
return response.WriteJSON(c, fiber.StatusOK, "Prematch odds retrieved successfully", odds, nil)
|
|
|
|
}
|