fix: date filter

This commit is contained in:
Samuel Tariku 2025-05-19 15:38:52 +03:00
parent 4c6fb73342
commit cdc40397b9
9 changed files with 41 additions and 12 deletions

View File

@ -158,9 +158,7 @@ SELECT id,
status, status,
fetched_at fetched_at
FROM events FROM events
WHERE is_live = false WHERE start_time < now()
AND status = 'upcoming'
AND start_time < now()
ORDER BY start_time ASC; ORDER BY start_time ASC;
-- name: GetTotalEvents :one -- name: GetTotalEvents :one
SELECT COUNT(*) SELECT COUNT(*)

View File

@ -1705,6 +1705,18 @@ const docTemplate = `{
"description": "Sport ID Filter", "description": "Sport ID Filter",
"name": "sport_id", "name": "sport_id",
"in": "query" "in": "query"
},
{
"type": "string",
"description": "Start Time",
"name": "first_start_time",
"in": "query"
},
{
"type": "string",
"description": "End Time",
"name": "last_start_time",
"in": "query"
} }
], ],
"responses": { "responses": {

View File

@ -1697,6 +1697,18 @@
"description": "Sport ID Filter", "description": "Sport ID Filter",
"name": "sport_id", "name": "sport_id",
"in": "query" "in": "query"
},
{
"type": "string",
"description": "Start Time",
"name": "first_start_time",
"in": "query"
},
{
"type": "string",
"description": "End Time",
"name": "last_start_time",
"in": "query"
} }
], ],
"responses": { "responses": {

View File

@ -2306,6 +2306,14 @@ paths:
in: query in: query
name: sport_id name: sport_id
type: string type: string
- description: Start Time
in: query
name: first_start_time
type: string
- description: End Time
in: query
name: last_start_time
type: string
produces: produces:
- application/json - application/json
responses: responses:

View File

@ -118,9 +118,7 @@ SELECT id,
status, status,
fetched_at fetched_at
FROM events FROM events
WHERE is_live = false WHERE start_time < now()
AND status = 'upcoming'
AND start_time < now()
ORDER BY start_time ASC ORDER BY start_time ASC
` `

View File

@ -133,7 +133,7 @@ func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, limit domain.Val
Valid: limit.Valid, Valid: limit.Valid,
}, },
Offset: pgtype.Int4{ Offset: pgtype.Int4{
Int32: int32(offset.Value), Int32: int32(offset.Value * limit.Value),
Valid: offset.Valid, Valid: offset.Valid,
}, },
FirstStartTime: pgtype.Timestamp{ FirstStartTime: pgtype.Timestamp{

View File

@ -99,8 +99,7 @@ func (s *service) FetchLiveEvents(ctx context.Context) error {
} }
func (s *service) FetchUpcomingEvents(ctx context.Context) error { func (s *service) FetchUpcomingEvents(ctx context.Context) error {
// sportIDs := []int{1, 18, 17} sportIDs := []int{1, 18, 17}
sportIDs := []int{18, 17}
for _, sportID := range sportIDs { for _, sportID := range sportIDs {
var totalPages int = 1 var totalPages int = 1
@ -142,7 +141,6 @@ func (s *service) FetchUpcomingEvents(ctx context.Context) error {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} `json:"away"` } `json:"away"`
} `json:"results"` } `json:"results"`
} }
if err := json.Unmarshal(body, &data); err != nil || data.Success != 1 { if err := json.Unmarshal(body, &data); err != nil || data.Success != 1 {
@ -165,7 +163,7 @@ func (s *service) FetchUpcomingEvents(ctx context.Context) error {
} }
if !slices.Contains(domain.SupportedLeagues, leagueID) { if !slices.Contains(domain.SupportedLeagues, leagueID) {
fmt.Printf("⚠️ Skipping league %s (%d) as it is not supported\n", ev.League.Name, leagueID) // fmt.Printf("⚠️ Skipping league %s (%d) as it is not supported\n", ev.League.Name, leagueID)
skippedLeague = append(skippedLeague, ev.League.Name) skippedLeague = append(skippedLeague, ev.League.Name)
continue continue
} }

View File

@ -52,6 +52,7 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
} }
for _, job := range schedule { for _, job := range schedule {
// job.task()
if _, err := c.AddFunc(job.spec, job.task); err != nil { if _, err := c.AddFunc(job.spec, job.task); err != nil {
log.Fatalf("Failed to schedule cron job: %v", err) log.Fatalf("Failed to schedule cron job: %v", err)
} }
@ -82,7 +83,6 @@ func StartTicketCrons(ticketService ticket.Service) {
} }
for _, job := range schedule { for _, job := range schedule {
job.task()
if _, err := c.AddFunc(job.spec, job.task); err != nil { if _, err := c.AddFunc(job.spec, job.task); err != nil {
log.Fatalf("Failed to schedule cron job: %v", err) log.Fatalf("Failed to schedule cron job: %v", err)
} }

View File

@ -99,6 +99,8 @@ func (h *Handler) GetRawOddsByMarketID(c *fiber.Ctx) error {
// @Param page_size query int false "Page size" // @Param page_size query int false "Page size"
// @Param league_id query string false "League ID Filter" // @Param league_id query string false "League ID Filter"
// @Param sport_id query string false "Sport ID Filter" // @Param sport_id query string false "Sport ID Filter"
// @Param first_start_time query string false "Start Time"
// @Param last_start_time query string false "End Time"
// @Success 200 {array} domain.UpcomingEvent // @Success 200 {array} domain.UpcomingEvent
// @Failure 500 {object} response.APIResponse // @Failure 500 {object} response.APIResponse
// @Router /prematch/events [get] // @Router /prematch/events [get]
@ -152,6 +154,7 @@ func (h *Handler) GetAllUpcomingEvents(c *fiber.Ctx) error {
Value: int64(page - 1), Value: int64(page - 1),
Valid: true, Valid: true,
} }
events, total, err := h.eventSvc.GetPaginatedUpcomingEvents( events, total, err := h.eventSvc.GetPaginatedUpcomingEvents(
c.Context(), limit, offset, leagueID, sportID, firstStartTime, lastStartTime) c.Context(), limit, offset, leagueID, sportID, firstStartTime, lastStartTime)