51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/response"
|
|
"github.com/gofiber/fiber/v2"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ResultRes struct {
|
|
ResultData json.RawMessage `json:"result_data" swaggerignore:"true"`
|
|
Outcomes []domain.BetOutcome `json:"outcomes"`
|
|
}
|
|
|
|
// This will take an event ID and return the success results for
|
|
// all the odds for that event.
|
|
// @Summary Get results for an event
|
|
// @Description Get results for an event
|
|
// @Tags result
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Event ID"
|
|
// @Success 200 {array} ResultRes
|
|
// @Failure 400 {object} response.APIResponse
|
|
// @Failure 500 {object} response.APIResponse
|
|
// @Router /api/v1/result/b365/{id} [get]
|
|
func (h *Handler) GetBet365ResultsByEventID(c *fiber.Ctx) error {
|
|
b365EventID := c.Params("id")
|
|
|
|
results, outcomes, err := h.resultSvc.GetBet365ResultForEvent(c.Context(), b365EventID)
|
|
if err != nil {
|
|
h.mongoLoggerSvc.Error("Failed to get results by Event ID",
|
|
zap.String("b365EventID", b365EventID),
|
|
zap.Int("status_code", fiber.StatusInternalServerError),
|
|
zap.Error(err),
|
|
zap.Time("timestamp", time.Now()),
|
|
)
|
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to retrieve results")
|
|
}
|
|
|
|
resultRes := ResultRes{
|
|
ResultData: results,
|
|
Outcomes: outcomes,
|
|
}
|
|
|
|
return response.WriteJSON(c, fiber.StatusOK, "Results retrieved successfully", resultRes, nil)
|
|
}
|