diff --git a/db/migrations/000001_fortune.up.sql b/db/migrations/000001_fortune.up.sql index c6c550d..89e20a8 100644 --- a/db/migrations/000001_fortune.up.sql +++ b/db/migrations/000001_fortune.up.sql @@ -297,7 +297,8 @@ CREATE TABLE IF NOT EXISTS branch_cashiers ( ); CREATE TABLE IF NOT EXISTS branch_locations (key TEXT PRIMARY KEY, value TEXT NOT NULL); CREATE TABLE events ( - id TEXT PRIMARY KEY, + id BIGSERIAL PRIMARY KEY, + source_event_id TEXT NOT NULL, sport_id INT NOT NULL, match_name TEXT NOT NULL, home_team TEXT NOT NULL, @@ -324,18 +325,18 @@ CREATE TABLE events ( default_is_featured BOOLEAN NOT NULL DEFAULT false, default_winning_upper_limit BIGINT NOT NULL, is_monitored BOOLEAN NOT NULL DEFAULT FALSE, - UNIQUE (id, source) + UNIQUE(source_event_id, source) ); CREATE TABLE event_history ( id BIGSERIAL PRIMARY KEY, - event_id TEXT NOT NULL, + event_id BIGINT NOT NULL, status TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE company_event_settings ( id BIGSERIAL PRIMARY KEY, company_id BIGINT NOT NULL, - event_id TEXT NOT NULL, + event_id BIGINT NOT NULL, is_active BOOLEAN, is_featured BOOLEAN, winning_upper_limit INT, @@ -344,11 +345,11 @@ CREATE TABLE company_event_settings ( ); CREATE TABLE odds_market ( id BIGSERIAL PRIMARY KEY, - event_id TEXT NOT NULL, + event_id BIGINT NOT NULL, market_type TEXT NOT NULL, market_name TEXT NOT NULL, market_category TEXT NOT NULL, - market_id TEXT NOT NULL, + market_id BIGINT NOT NULL, raw_odds JSONB NOT NULL, default_is_active BOOLEAN NOT NULL DEFAULT true, fetched_at TIMESTAMP DEFAULT now (), @@ -359,8 +360,8 @@ CREATE TABLE odd_history ( id BIGSERIAL PRIMARY KEY, odds_market_id BIGINT NOT NULL REFERENCES odds_market (id), raw_odd_id BIGINT NOT NULL, - market_id TEXT NOT NULL, - event_id TEXT NOT NULL, + market_id BIGINT NOT NULL, + event_id BIGINT NOT NULL, odd_value DOUBLE PRECISION NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); @@ -369,7 +370,7 @@ CREATE TABLE disabled_odd ( company_id BIGINT NOT NULL, odds_market_id BIGINT NOT NULL, raw_odd_id BIGINT NOT NULL, - event_id TEXT NOT NULL, + event_id BIGINT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE company_odd_settings ( diff --git a/db/query/events.sql b/db/query/events.sql index c5ec974..ff7b03f 100644 --- a/db/query/events.sql +++ b/db/query/events.sql @@ -1,6 +1,6 @@ -- name: InsertEvent :exec INSERT INTO events ( - id, + source_event_id, sport_id, match_name, home_team, @@ -34,7 +34,7 @@ VALUES ( $14, $15, $16 - ) ON CONFLICT (id) DO + ) ON CONFLICT (source_event_id, source) DO UPDATE SET sport_id = EXCLUDED.sport_id, match_name = EXCLUDED.match_name, @@ -73,27 +73,17 @@ SET is_active = EXCLUDED.is_active, SELECT id FROM event_with_country WHERE is_live = true; --- name: GetAllUpcomingEvents :many +-- name: GetAllEvents :many SELECT * FROM event_with_country -WHERE start_time > now() - AND is_live = false - AND status = 'upcoming' -ORDER BY start_time ASC; --- name: GetExpiredEvents :many -SELECT * -FROM event_with_country -WHERE start_time < now() - and ( +WHERE ( + is_live = sqlc.narg('is_live') + OR sqlc.narg('is_live') IS NULL + ) + AND ( status = sqlc.narg('status') OR sqlc.narg('status') IS NULL ) -ORDER BY start_time ASC; --- name: GetTotalEvents :one -SELECT COUNT(*) -FROM event_with_country -WHERE is_live = false - AND status = 'upcoming' AND ( league_id = sqlc.narg('league_id') OR sqlc.narg('league_id') IS NULL @@ -118,49 +108,68 @@ WHERE is_live = false AND ( league_cc = sqlc.narg('country_code') OR sqlc.narg('country_code') IS NULL - ); --- name: GetPaginatedUpcomingEvents :many -SELECT * -FROM event_with_country -WHERE start_time > now() - AND is_live = false - AND status = 'upcoming' - AND ( - league_id = sqlc.narg('league_id') - OR sqlc.narg('league_id') IS NULL ) AND ( - sport_id = sqlc.narg('sport_id') - OR sqlc.narg('sport_id') IS NULL - ) - AND ( - match_name ILIKE '%' || sqlc.narg('query') || '%' - OR league_name ILIKE '%' || sqlc.narg('query') || '%' - OR sqlc.narg('query') IS NULL - ) - AND ( - start_time < sqlc.narg('last_start_time') - OR sqlc.narg('last_start_time') IS NULL - ) - AND ( - start_time > sqlc.narg('first_start_time') - OR sqlc.narg('first_start_time') IS NULL - ) - AND ( - league_cc = sqlc.narg('country_code') - OR sqlc.narg('country_code') IS NULL + source = sqlc.narg('source') + OR sqlc.narg('source') IS NULL ) ORDER BY start_time ASC LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset'); +-- name: GetTotalEvents :one +SELECT COUNT(*) +FROM event_with_country +WHERE ( + is_live = sqlc.narg('is_live') + OR sqlc.narg('is_live') IS NULL + ) + AND ( + status = sqlc.narg('status') + OR sqlc.narg('status') IS NULL + ) + AND ( + league_id = sqlc.narg('league_id') + OR sqlc.narg('league_id') IS NULL + ) + AND ( + sport_id = sqlc.narg('sport_id') + OR sqlc.narg('sport_id') IS NULL + ) + AND ( + match_name ILIKE '%' || sqlc.narg('query') || '%' + OR league_name ILIKE '%' || sqlc.narg('query') || '%' + OR sqlc.narg('query') IS NULL + ) + AND ( + start_time < sqlc.narg('last_start_time') + OR sqlc.narg('last_start_time') IS NULL + ) + AND ( + start_time > sqlc.narg('first_start_time') + OR sqlc.narg('first_start_time') IS NULL + ) + AND ( + league_cc = sqlc.narg('country_code') + OR sqlc.narg('country_code') IS NULL + ) + AND ( + source = sqlc.narg('source') + OR sqlc.narg('source') IS NULL + ); -- name: GetTotalCompanyEvents :one SELECT COUNT(*) FROM events e LEFT JOIN company_event_settings ces ON e.id = ces.event_id AND ces.company_id = $1 JOIN leagues l ON l.id = e.league_id -WHERE is_live = false - AND status = 'upcoming' +WHERE ( + is_live = sqlc.narg('is_live') + OR sqlc.narg('is_live') IS NULL + ) AND ( + status = sqlc.narg('status') + OR sqlc.narg('status') IS NULL + ) + AND( league_id = sqlc.narg('league_id') OR sqlc.narg('league_id') IS NULL ) @@ -194,6 +203,10 @@ WHERE is_live = false ces.is_active = sqlc.narg('is_active') OR e.default_is_active = sqlc.narg('is_active') OR sqlc.narg('is_active') IS NULL + ) + AND ( + source = sqlc.narg('source') + OR sqlc.narg('source') IS NULL ); -- name: GetEventsWithSettings :many SELECT e.*, @@ -210,10 +223,15 @@ FROM events e LEFT JOIN company_event_settings ces ON e.id = ces.event_id AND ces.company_id = $1 JOIN leagues l ON l.id = e.league_id -WHERE start_time > now() - AND is_live = false - AND status = 'upcoming' +WHERE ( + is_live = sqlc.narg('is_live') + OR sqlc.narg('is_live') IS NULL + ) AND ( + status = sqlc.narg('status') + OR sqlc.narg('status') IS NULL + ) + AND( league_id = sqlc.narg('league_id') OR sqlc.narg('league_id') IS NULL ) @@ -248,15 +266,22 @@ WHERE start_time > now() OR e.default_is_active = sqlc.narg('is_active') OR sqlc.narg('is_active') IS NULL ) + AND ( + source = sqlc.narg('source') + OR sqlc.narg('source') IS NULL + ) ORDER BY start_time ASC LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset'); --- name: GetUpcomingByID :one +-- name: GetEventByID :one SELECT * FROM event_with_country WHERE id = $1 - AND is_live = false - AND status = 'upcoming' LIMIT 1; +-- name: GetEventBySourceID :one +SELECT * +FROM event_with_country +WHERE source_event_id = $1 + AND source = $2; -- name: GetEventWithSettingByID :one SELECT e.*, ces.company_id, @@ -273,8 +298,6 @@ FROM events e AND ces.company_id = $2 JOIN leagues l ON l.id = e.league_id WHERE e.id = $1 - AND is_live = false - AND status = 'upcoming' LIMIT 1; -- name: GetSportAndLeagueIDs :one SELECT sport_id, league_id FROM events diff --git a/gen/db/disabled_odds.sql.go b/gen/db/disabled_odds.sql.go index 917acce..58913cf 100644 --- a/gen/db/disabled_odds.sql.go +++ b/gen/db/disabled_odds.sql.go @@ -113,10 +113,10 @@ RETURNING id, company_id, odds_market_id, raw_odd_id, event_id, created_at ` type InsertDisabledOddsParams struct { - OddsMarketID int64 `json:"odds_market_id"` - CompanyID int64 `json:"company_id"` - EventID string `json:"event_id"` - RawOddID int64 `json:"raw_odd_id"` + OddsMarketID int64 `json:"odds_market_id"` + CompanyID int64 `json:"company_id"` + EventID int64 `json:"event_id"` + RawOddID int64 `json:"raw_odd_id"` } func (q *Queries) InsertDisabledOdds(ctx context.Context, arg InsertDisabledOddsParams) (DisabledOdd, error) { diff --git a/gen/db/event_history.sql.go b/gen/db/event_history.sql.go index 64762c3..35946cd 100644 --- a/gen/db/event_history.sql.go +++ b/gen/db/event_history.sql.go @@ -29,7 +29,7 @@ WHERE ( ` type GetAllEventHistoryParams struct { - EventID pgtype.Text `json:"event_id"` + EventID pgtype.Int8 `json:"event_id"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } @@ -79,7 +79,7 @@ ORDER BY DATE_TRUNC('day', created_at), ` type GetInitialEventPerDayParams struct { - EventID pgtype.Text `json:"event_id"` + EventID pgtype.Int8 `json:"event_id"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } @@ -116,7 +116,7 @@ RETURNING id, event_id, status, created_at ` type InsertEventHistoryParams struct { - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` Status string `json:"status"` } diff --git a/gen/db/events.sql.go b/gen/db/events.sql.go index 9c9afe7..0729560 100644 --- a/gen/db/events.sql.go +++ b/gen/db/events.sql.go @@ -16,22 +16,83 @@ DELETE FROM events WHERE id = $1 ` -func (q *Queries) DeleteEvent(ctx context.Context, id string) error { +func (q *Queries) DeleteEvent(ctx context.Context, id int64) error { _, err := q.db.Exec(ctx, DeleteEvent, id) return err } -const GetAllUpcomingEvents = `-- name: GetAllUpcomingEvents :many -SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc +const GetAllEvents = `-- name: GetAllEvents :many +SELECT id, source_event_id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc FROM event_with_country -WHERE start_time > now() - AND is_live = false - AND status = 'upcoming' +WHERE ( + is_live = $1 + OR $1 IS NULL + ) + AND ( + status = $2 + OR $2 IS NULL + ) + AND ( + league_id = $3 + OR $3 IS NULL + ) + AND ( + sport_id = $4 + OR $4 IS NULL + ) + AND ( + match_name ILIKE '%' || $5 || '%' + OR league_name ILIKE '%' || $5 || '%' + OR $5 IS NULL + ) + AND ( + start_time < $6 + OR $6 IS NULL + ) + AND ( + start_time > $7 + OR $7 IS NULL + ) + AND ( + league_cc = $8 + OR $8 IS NULL + ) + AND ( + source = $9 + OR $9 IS NULL + ) ORDER BY start_time ASC +LIMIT $11 OFFSET $10 ` -func (q *Queries) GetAllUpcomingEvents(ctx context.Context) ([]EventWithCountry, error) { - rows, err := q.db.Query(ctx, GetAllUpcomingEvents) +type GetAllEventsParams struct { + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` + LeagueID pgtype.Int8 `json:"league_id"` + SportID pgtype.Int4 `json:"sport_id"` + Query pgtype.Text `json:"query"` + LastStartTime pgtype.Timestamp `json:"last_start_time"` + FirstStartTime pgtype.Timestamp `json:"first_start_time"` + CountryCode pgtype.Text `json:"country_code"` + Source pgtype.Text `json:"source"` + Offset pgtype.Int4 `json:"offset"` + Limit pgtype.Int4 `json:"limit"` +} + +func (q *Queries) GetAllEvents(ctx context.Context, arg GetAllEventsParams) ([]EventWithCountry, error) { + rows, err := q.db.Query(ctx, GetAllEvents, + arg.IsLive, + arg.Status, + arg.LeagueID, + arg.SportID, + arg.Query, + arg.LastStartTime, + arg.FirstStartTime, + arg.CountryCode, + arg.Source, + arg.Offset, + arg.Limit, + ) if err != nil { return nil, err } @@ -41,6 +102,7 @@ func (q *Queries) GetAllUpcomingEvents(ctx context.Context) ([]EventWithCountry, var i EventWithCountry if err := rows.Scan( &i.ID, + &i.SourceEventID, &i.SportID, &i.MatchName, &i.HomeTeam, @@ -77,8 +139,97 @@ func (q *Queries) GetAllUpcomingEvents(ctx context.Context) ([]EventWithCountry, return items, nil } +const GetEventByID = `-- name: GetEventByID :one +SELECT id, source_event_id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc +FROM event_with_country +WHERE id = $1 +LIMIT 1 +` + +func (q *Queries) GetEventByID(ctx context.Context, id int64) (EventWithCountry, error) { + row := q.db.QueryRow(ctx, GetEventByID, id) + var i EventWithCountry + err := row.Scan( + &i.ID, + &i.SourceEventID, + &i.SportID, + &i.MatchName, + &i.HomeTeam, + &i.AwayTeam, + &i.HomeTeamID, + &i.AwayTeamID, + &i.HomeKitImage, + &i.AwayKitImage, + &i.LeagueID, + &i.LeagueName, + &i.StartTime, + &i.Score, + &i.MatchMinute, + &i.TimerStatus, + &i.AddedTime, + &i.MatchPeriod, + &i.IsLive, + &i.Status, + &i.FetchedAt, + &i.Source, + &i.DefaultIsActive, + &i.DefaultIsFeatured, + &i.DefaultWinningUpperLimit, + &i.IsMonitored, + &i.LeagueCc, + ) + return i, err +} + +const GetEventBySourceID = `-- name: GetEventBySourceID :one +SELECT id, source_event_id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc +FROM event_with_country +WHERE source_event_id = $1 + AND source = $2 +` + +type GetEventBySourceIDParams struct { + SourceEventID string `json:"source_event_id"` + Source string `json:"source"` +} + +func (q *Queries) GetEventBySourceID(ctx context.Context, arg GetEventBySourceIDParams) (EventWithCountry, error) { + row := q.db.QueryRow(ctx, GetEventBySourceID, arg.SourceEventID, arg.Source) + var i EventWithCountry + err := row.Scan( + &i.ID, + &i.SourceEventID, + &i.SportID, + &i.MatchName, + &i.HomeTeam, + &i.AwayTeam, + &i.HomeTeamID, + &i.AwayTeamID, + &i.HomeKitImage, + &i.AwayKitImage, + &i.LeagueID, + &i.LeagueName, + &i.StartTime, + &i.Score, + &i.MatchMinute, + &i.TimerStatus, + &i.AddedTime, + &i.MatchPeriod, + &i.IsLive, + &i.Status, + &i.FetchedAt, + &i.Source, + &i.DefaultIsActive, + &i.DefaultIsFeatured, + &i.DefaultWinningUpperLimit, + &i.IsMonitored, + &i.LeagueCc, + ) + return i, err +} + const GetEventWithSettingByID = `-- name: GetEventWithSettingByID :one -SELECT e.id, e.sport_id, e.match_name, e.home_team, e.away_team, e.home_team_id, e.away_team_id, e.home_kit_image, e.away_kit_image, e.league_id, e.league_name, e.start_time, e.score, e.match_minute, e.timer_status, e.added_time, e.match_period, e.is_live, e.status, e.fetched_at, e.source, e.default_is_active, e.default_is_featured, e.default_winning_upper_limit, e.is_monitored, +SELECT e.id, e.source_event_id, e.sport_id, e.match_name, e.home_team, e.away_team, e.home_team_id, e.away_team_id, e.home_kit_image, e.away_kit_image, e.league_id, e.league_name, e.start_time, e.score, e.match_minute, e.timer_status, e.added_time, e.match_period, e.is_live, e.status, e.fetched_at, e.source, e.default_is_active, e.default_is_featured, e.default_winning_upper_limit, e.is_monitored, ces.company_id, COALESCE(ces.is_active, e.default_is_active) AS is_active, COALESCE(ces.is_featured, e.default_is_featured) AS is_featured, @@ -93,18 +244,17 @@ FROM events e AND ces.company_id = $2 JOIN leagues l ON l.id = e.league_id WHERE e.id = $1 - AND is_live = false - AND status = 'upcoming' LIMIT 1 ` type GetEventWithSettingByIDParams struct { - ID string `json:"id"` - CompanyID int64 `json:"company_id"` + ID int64 `json:"id"` + CompanyID int64 `json:"company_id"` } type GetEventWithSettingByIDRow struct { - ID string `json:"id"` + ID int64 `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -142,6 +292,7 @@ func (q *Queries) GetEventWithSettingByID(ctx context.Context, arg GetEventWithS var i GetEventWithSettingByIDRow err := row.Scan( &i.ID, + &i.SourceEventID, &i.SportID, &i.MatchName, &i.HomeTeam, @@ -177,7 +328,7 @@ func (q *Queries) GetEventWithSettingByID(ctx context.Context, arg GetEventWithS } const GetEventsWithSettings = `-- name: GetEventsWithSettings :many -SELECT e.id, e.sport_id, e.match_name, e.home_team, e.away_team, e.home_team_id, e.away_team_id, e.home_kit_image, e.away_kit_image, e.league_id, e.league_name, e.start_time, e.score, e.match_minute, e.timer_status, e.added_time, e.match_period, e.is_live, e.status, e.fetched_at, e.source, e.default_is_active, e.default_is_featured, e.default_winning_upper_limit, e.is_monitored, +SELECT e.id, e.source_event_id, e.sport_id, e.match_name, e.home_team, e.away_team, e.home_team_id, e.away_team_id, e.home_kit_image, e.away_kit_image, e.league_id, e.league_name, e.start_time, e.score, e.match_minute, e.timer_status, e.added_time, e.match_period, e.is_live, e.status, e.fetched_at, e.source, e.default_is_active, e.default_is_featured, e.default_winning_upper_limit, e.is_monitored, ces.company_id, COALESCE(ces.is_active, e.default_is_active) AS is_active, COALESCE(ces.is_featured, e.default_is_featured) AS is_featured, @@ -191,50 +342,61 @@ FROM events e LEFT JOIN company_event_settings ces ON e.id = ces.event_id AND ces.company_id = $1 JOIN leagues l ON l.id = e.league_id -WHERE start_time > now() - AND is_live = false - AND status = 'upcoming' - AND ( - league_id = $2 +WHERE ( + is_live = $2 OR $2 IS NULL ) AND ( - e.sport_id = $3 + status = $3 OR $3 IS NULL ) - AND ( - match_name ILIKE '%' || $4 || '%' - OR league_name ILIKE '%' || $4 || '%' + AND( + league_id = $4 OR $4 IS NULL ) AND ( - start_time < $5 + e.sport_id = $5 OR $5 IS NULL ) AND ( - start_time > $6 + match_name ILIKE '%' || $6 || '%' + OR league_name ILIKE '%' || $6 || '%' OR $6 IS NULL ) AND ( - l.country_code = $7 + start_time < $7 OR $7 IS NULL ) AND ( - ces.is_featured = $8 - OR e.default_is_featured = $8 + start_time > $8 OR $8 IS NULL ) AND ( - ces.is_active = $9 - OR e.default_is_active = $9 + l.country_code = $9 OR $9 IS NULL ) + AND ( + ces.is_featured = $10 + OR e.default_is_featured = $10 + OR $10 IS NULL + ) + AND ( + ces.is_active = $11 + OR e.default_is_active = $11 + OR $11 IS NULL + ) + AND ( + source = $12 + OR $12 IS NULL + ) ORDER BY start_time ASC -LIMIT $11 OFFSET $10 +LIMIT $14 OFFSET $13 ` type GetEventsWithSettingsParams struct { CompanyID int64 `json:"company_id"` + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` LeagueID pgtype.Int8 `json:"league_id"` SportID pgtype.Int4 `json:"sport_id"` Query pgtype.Text `json:"query"` @@ -243,12 +405,14 @@ type GetEventsWithSettingsParams struct { CountryCode pgtype.Text `json:"country_code"` IsFeatured pgtype.Bool `json:"is_featured"` IsActive pgtype.Bool `json:"is_active"` + Source pgtype.Text `json:"source"` Offset pgtype.Int4 `json:"offset"` Limit pgtype.Int4 `json:"limit"` } type GetEventsWithSettingsRow struct { - ID string `json:"id"` + ID int64 `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -284,6 +448,8 @@ type GetEventsWithSettingsRow struct { func (q *Queries) GetEventsWithSettings(ctx context.Context, arg GetEventsWithSettingsParams) ([]GetEventsWithSettingsRow, error) { rows, err := q.db.Query(ctx, GetEventsWithSettings, arg.CompanyID, + arg.IsLive, + arg.Status, arg.LeagueID, arg.SportID, arg.Query, @@ -292,6 +458,7 @@ func (q *Queries) GetEventsWithSettings(ctx context.Context, arg GetEventsWithSe arg.CountryCode, arg.IsFeatured, arg.IsActive, + arg.Source, arg.Offset, arg.Limit, ) @@ -304,6 +471,7 @@ func (q *Queries) GetEventsWithSettings(ctx context.Context, arg GetEventsWithSe var i GetEventsWithSettingsRow if err := rows.Scan( &i.ID, + &i.SourceEventID, &i.SportID, &i.MatchName, &i.HomeTeam, @@ -528,47 +696,59 @@ FROM events e LEFT JOIN company_event_settings ces ON e.id = ces.event_id AND ces.company_id = $1 JOIN leagues l ON l.id = e.league_id -WHERE is_live = false - AND status = 'upcoming' - AND ( - league_id = $2 +WHERE ( + is_live = $2 OR $2 IS NULL ) AND ( - e.sport_id = $3 + status = $3 OR $3 IS NULL ) - AND ( - match_name ILIKE '%' || $4 || '%' - OR league_name ILIKE '%' || $4 || '%' + AND( + league_id = $4 OR $4 IS NULL ) AND ( - start_time < $5 + e.sport_id = $5 OR $5 IS NULL ) AND ( - start_time > $6 + match_name ILIKE '%' || $6 || '%' + OR league_name ILIKE '%' || $6 || '%' OR $6 IS NULL ) AND ( - l.country_code = $7 + start_time < $7 OR $7 IS NULL ) AND ( - ces.is_featured = $8 - OR e.default_is_featured = $8 + start_time > $8 OR $8 IS NULL ) AND ( - ces.is_active = $9 - OR e.default_is_active = $9 + l.country_code = $9 OR $9 IS NULL ) + AND ( + ces.is_featured = $10 + OR e.default_is_featured = $10 + OR $10 IS NULL + ) + AND ( + ces.is_active = $11 + OR e.default_is_active = $11 + OR $11 IS NULL + ) + AND ( + source = $12 + OR $12 IS NULL + ) ` type GetTotalCompanyEventsParams struct { CompanyID int64 `json:"company_id"` + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` LeagueID pgtype.Int8 `json:"league_id"` SportID pgtype.Int4 `json:"sport_id"` Query pgtype.Text `json:"query"` @@ -577,11 +757,14 @@ type GetTotalCompanyEventsParams struct { CountryCode pgtype.Text `json:"country_code"` IsFeatured pgtype.Bool `json:"is_featured"` IsActive pgtype.Bool `json:"is_active"` + Source pgtype.Text `json:"source"` } func (q *Queries) GetTotalCompanyEvents(ctx context.Context, arg GetTotalCompanyEventsParams) (int64, error) { row := q.db.QueryRow(ctx, GetTotalCompanyEvents, arg.CompanyID, + arg.IsLive, + arg.Status, arg.LeagueID, arg.SportID, arg.Query, @@ -590,6 +773,7 @@ func (q *Queries) GetTotalCompanyEvents(ctx context.Context, arg GetTotalCompany arg.CountryCode, arg.IsFeatured, arg.IsActive, + arg.Source, ) var count int64 err := row.Scan(&count) @@ -599,104 +783,77 @@ func (q *Queries) GetTotalCompanyEvents(ctx context.Context, arg GetTotalCompany const GetTotalEvents = `-- name: GetTotalEvents :one SELECT COUNT(*) FROM event_with_country -WHERE is_live = false - AND status = 'upcoming' - AND ( - league_id = $1 +WHERE ( + is_live = $1 OR $1 IS NULL ) AND ( - sport_id = $2 + status = $2 OR $2 IS NULL ) AND ( - match_name ILIKE '%' || $3 || '%' - OR league_name ILIKE '%' || $3 || '%' + league_id = $3 OR $3 IS NULL ) AND ( - start_time < $4 + sport_id = $4 OR $4 IS NULL ) AND ( - start_time > $5 + match_name ILIKE '%' || $5 || '%' + OR league_name ILIKE '%' || $5 || '%' OR $5 IS NULL ) AND ( - league_cc = $6 + start_time < $6 OR $6 IS NULL ) + AND ( + start_time > $7 + OR $7 IS NULL + ) + AND ( + league_cc = $8 + OR $8 IS NULL + ) + AND ( + source = $9 + OR $9 IS NULL + ) ` type GetTotalEventsParams struct { + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` LeagueID pgtype.Int8 `json:"league_id"` SportID pgtype.Int4 `json:"sport_id"` Query pgtype.Text `json:"query"` LastStartTime pgtype.Timestamp `json:"last_start_time"` FirstStartTime pgtype.Timestamp `json:"first_start_time"` CountryCode pgtype.Text `json:"country_code"` + Source pgtype.Text `json:"source"` } func (q *Queries) GetTotalEvents(ctx context.Context, arg GetTotalEventsParams) (int64, error) { row := q.db.QueryRow(ctx, GetTotalEvents, + arg.IsLive, + arg.Status, arg.LeagueID, arg.SportID, arg.Query, arg.LastStartTime, arg.FirstStartTime, arg.CountryCode, + arg.Source, ) var count int64 err := row.Scan(&count) return count, err } -const GetUpcomingByID = `-- name: GetUpcomingByID :one -SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc -FROM event_with_country -WHERE id = $1 - AND is_live = false - AND status = 'upcoming' -LIMIT 1 -` - -func (q *Queries) GetUpcomingByID(ctx context.Context, id string) (EventWithCountry, error) { - row := q.db.QueryRow(ctx, GetUpcomingByID, id) - var i EventWithCountry - err := row.Scan( - &i.ID, - &i.SportID, - &i.MatchName, - &i.HomeTeam, - &i.AwayTeam, - &i.HomeTeamID, - &i.AwayTeamID, - &i.HomeKitImage, - &i.AwayKitImage, - &i.LeagueID, - &i.LeagueName, - &i.StartTime, - &i.Score, - &i.MatchMinute, - &i.TimerStatus, - &i.AddedTime, - &i.MatchPeriod, - &i.IsLive, - &i.Status, - &i.FetchedAt, - &i.Source, - &i.DefaultIsActive, - &i.DefaultIsFeatured, - &i.DefaultWinningUpperLimit, - &i.IsMonitored, - &i.LeagueCc, - ) - return i, err -} - const InsertEvent = `-- name: InsertEvent :exec INSERT INTO events ( - id, + source_event_id, sport_id, match_name, home_team, @@ -730,7 +887,7 @@ VALUES ( $14, $15, $16 - ) ON CONFLICT (id) DO + ) ON CONFLICT (source_event_id, source) DO UPDATE SET sport_id = EXCLUDED.sport_id, match_name = EXCLUDED.match_name, @@ -755,7 +912,7 @@ SET sport_id = EXCLUDED.sport_id, ` type InsertEventParams struct { - ID string `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -775,7 +932,7 @@ type InsertEventParams struct { func (q *Queries) InsertEvent(ctx context.Context, arg InsertEventParams) error { _, err := q.db.Exec(ctx, InsertEvent, - arg.ID, + arg.SourceEventID, arg.SportID, arg.MatchName, arg.HomeTeam, @@ -801,7 +958,7 @@ FROM events WHERE id = $1 ` -func (q *Queries) IsEventMonitored(ctx context.Context, id string) (bool, error) { +func (q *Queries) IsEventMonitored(ctx context.Context, id int64) (bool, error) { row := q.db.QueryRow(ctx, IsEventMonitored, id) var is_monitored bool err := row.Scan(&is_monitored) @@ -814,15 +971,15 @@ FROM event_with_country WHERE is_live = true ` -func (q *Queries) ListLiveEvents(ctx context.Context) ([]string, error) { +func (q *Queries) ListLiveEvents(ctx context.Context) ([]int64, error) { rows, err := q.db.Query(ctx, ListLiveEvents) if err != nil { return nil, err } defer rows.Close() - var items []string + var items []int64 for rows.Next() { - var id string + var id int64 if err := rows.Scan(&id); err != nil { return nil, err } @@ -851,7 +1008,7 @@ SET is_active = EXCLUDED.is_active, type SaveEventSettingsParams struct { CompanyID int64 `json:"company_id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` IsActive pgtype.Bool `json:"is_active"` IsFeatured pgtype.Bool `json:"is_featured"` WinningUpperLimit pgtype.Int4 `json:"winning_upper_limit"` @@ -875,8 +1032,8 @@ WHERE id = $2 ` type UpdateEventMonitoredParams struct { - IsMonitored bool `json:"is_monitored"` - ID string `json:"id"` + IsMonitored bool `json:"is_monitored"` + ID int64 `json:"id"` } func (q *Queries) UpdateEventMonitored(ctx context.Context, arg UpdateEventMonitoredParams) error { @@ -894,7 +1051,7 @@ WHERE id = $3 type UpdateMatchResultParams struct { Score pgtype.Text `json:"score"` Status string `json:"status"` - ID string `json:"id"` + ID int64 `json:"id"` } func (q *Queries) UpdateMatchResult(ctx context.Context, arg UpdateMatchResultParams) error { diff --git a/gen/db/models.go b/gen/db/models.go index 1e27632..7a3d25f 100644 --- a/gen/db/models.go +++ b/gen/db/models.go @@ -162,7 +162,7 @@ type Company struct { type CompanyEventSetting struct { ID int64 `json:"id"` CompanyID int64 `json:"company_id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` IsActive pgtype.Bool `json:"is_active"` IsFeatured pgtype.Bool `json:"is_featured"` WinningUpperLimit pgtype.Int4 `json:"winning_upper_limit"` @@ -240,12 +240,13 @@ type DisabledOdd struct { CompanyID int64 `json:"company_id"` OddsMarketID int64 `json:"odds_market_id"` RawOddID int64 `json:"raw_odd_id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` CreatedAt pgtype.Timestamp `json:"created_at"` } type Event struct { - ID string `json:"id"` + ID int64 `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -274,13 +275,14 @@ type Event struct { type EventHistory struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` Status string `json:"status"` CreatedAt pgtype.Timestamp `json:"created_at"` } type EventWithCountry struct { - ID string `json:"id"` + ID int64 `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -309,7 +311,8 @@ type EventWithCountry struct { } type EventWithSetting struct { - ID string `json:"id"` + ID int64 `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -421,19 +424,19 @@ type OddHistory struct { ID int64 `json:"id"` OddsMarketID int64 `json:"odds_market_id"` RawOddID int64 `json:"raw_odd_id"` - MarketID string `json:"market_id"` - EventID string `json:"event_id"` + MarketID int64 `json:"market_id"` + EventID int64 `json:"event_id"` OddValue float64 `json:"odd_value"` CreatedAt pgtype.Timestamp `json:"created_at"` } type OddsMarket struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` RawOdds []byte `json:"raw_odds"` DefaultIsActive bool `json:"default_is_active"` FetchedAt pgtype.Timestamp `json:"fetched_at"` @@ -442,11 +445,11 @@ type OddsMarket struct { type OddsMarketWithEvent struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` RawOdds []byte `json:"raw_odds"` DefaultIsActive bool `json:"default_is_active"` FetchedAt pgtype.Timestamp `json:"fetched_at"` @@ -459,11 +462,11 @@ type OddsMarketWithEvent struct { type OddsMarketWithSetting struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` DefaultIsActive bool `json:"default_is_active"` FetchedAt pgtype.Timestamp `json:"fetched_at"` ExpiresAt pgtype.Timestamp `json:"expires_at"` diff --git a/gen/db/odd_history.sql.go b/gen/db/odd_history.sql.go index dd69a51..dd834c5 100644 --- a/gen/db/odd_history.sql.go +++ b/gen/db/odd_history.sql.go @@ -42,9 +42,9 @@ WHERE ( type GetAllOddHistoryParams struct { OddID pgtype.Int8 `json:"odd_id"` - MarketID pgtype.Text `json:"market_id"` + MarketID pgtype.Int8 `json:"market_id"` RawOddID pgtype.Int8 `json:"raw_odd_id"` - EventID pgtype.Text `json:"event_id"` + EventID pgtype.Int8 `json:"event_id"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } @@ -118,9 +118,9 @@ ORDER BY DATE_TRUNC($1, created_at), type GetInitialOddPerDayParams struct { DateTrunc string `json:"date_trunc"` OddID pgtype.Int8 `json:"odd_id"` - MarketID pgtype.Text `json:"market_id"` + MarketID pgtype.Int8 `json:"market_id"` RawOddID pgtype.Int8 `json:"raw_odd_id"` - EventID pgtype.Text `json:"event_id"` + EventID pgtype.Int8 `json:"event_id"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } @@ -175,9 +175,9 @@ RETURNING id, odds_market_id, raw_odd_id, market_id, event_id, odd_value, create type InsertOddHistoryParams struct { OddsMarketID int64 `json:"odds_market_id"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` RawOddID int64 `json:"raw_odd_id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` OddValue float64 `json:"odd_value"` } diff --git a/gen/db/odds.sql.go b/gen/db/odds.sql.go index d194d14..1f181e4 100644 --- a/gen/db/odds.sql.go +++ b/gen/db/odds.sql.go @@ -16,7 +16,7 @@ DELETE FROM odds_market Where event_id = $1 ` -func (q *Queries) DeleteOddsForEvent(ctx context.Context, eventID string) error { +func (q *Queries) DeleteOddsForEvent(ctx context.Context, eventID int64) error { _, err := q.db.Exec(ctx, DeleteOddsForEvent, eventID) return err } @@ -95,11 +95,11 @@ type GetAllOddsWithSettingsParams struct { type GetAllOddsWithSettingsRow struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` DefaultIsActive bool `json:"default_is_active"` FetchedAt pgtype.Timestamp `json:"fetched_at"` ExpiresAt pgtype.Timestamp `json:"expires_at"` @@ -191,7 +191,7 @@ LIMIT $6 OFFSET $5 ` type GetOddsByEventIDParams struct { - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` IsLive pgtype.Bool `json:"is_live"` Status pgtype.Text `json:"status"` Source pgtype.Text `json:"source"` @@ -249,8 +249,8 @@ WHERE market_id = $1 ` type GetOddsByMarketIDParams struct { - MarketID string `json:"market_id"` - EventID string `json:"event_id"` + MarketID int64 `json:"market_id"` + EventID int64 `json:"event_id"` } func (q *Queries) GetOddsByMarketID(ctx context.Context, arg GetOddsByMarketIDParams) (OddsMarketWithEvent, error) { @@ -297,7 +297,7 @@ LIMIT $4 OFFSET $3 ` type GetOddsWithSettingsByEventIDParams struct { - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` CompanyID int64 `json:"company_id"` Offset pgtype.Int4 `json:"offset"` Limit pgtype.Int4 `json:"limit"` @@ -305,11 +305,11 @@ type GetOddsWithSettingsByEventIDParams struct { type GetOddsWithSettingsByEventIDRow struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` DefaultIsActive bool `json:"default_is_active"` FetchedAt pgtype.Timestamp `json:"fetched_at"` ExpiresAt pgtype.Timestamp `json:"expires_at"` @@ -385,11 +385,11 @@ type GetOddsWithSettingsByIDParams struct { type GetOddsWithSettingsByIDRow struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` DefaultIsActive bool `json:"default_is_active"` FetchedAt pgtype.Timestamp `json:"fetched_at"` ExpiresAt pgtype.Timestamp `json:"expires_at"` @@ -442,18 +442,18 @@ WHERE market_id = $1 ` type GetOddsWithSettingsByMarketIDParams struct { - MarketID string `json:"market_id"` - EventID string `json:"event_id"` - CompanyID int64 `json:"company_id"` + MarketID int64 `json:"market_id"` + EventID int64 `json:"event_id"` + CompanyID int64 `json:"company_id"` } type GetOddsWithSettingsByMarketIDRow struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` DefaultIsActive bool `json:"default_is_active"` FetchedAt pgtype.Timestamp `json:"fetched_at"` ExpiresAt pgtype.Timestamp `json:"expires_at"` @@ -515,11 +515,11 @@ SET market_type = EXCLUDED.market_type, ` type InsertOddsMarketParams struct { - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` RawOdds []byte `json:"raw_odds"` FetchedAt pgtype.Timestamp `json:"fetched_at"` ExpiresAt pgtype.Timestamp `json:"expires_at"` diff --git a/internal/domain/disabled_odds.go b/internal/domain/disabled_odds.go index 2a3c83c..737c6b5 100644 --- a/internal/domain/disabled_odds.go +++ b/internal/domain/disabled_odds.go @@ -10,7 +10,7 @@ type DisabledOdd struct { ID int64 OddMarketID int64 RawOddID int64 - EventID string + EventID int64 CompanyID int64 CreatedAt time.Time } @@ -18,7 +18,7 @@ type DisabledOdd struct { type CreateDisabledOdd struct { OddMarketID int64 RawOddID int64 - EventID string + EventID int64 CompanyID int64 } diff --git a/internal/domain/event.go b/internal/domain/event.go index 152f1de..d898150 100644 --- a/internal/domain/event.go +++ b/internal/domain/event.go @@ -51,7 +51,8 @@ const ( ) type BaseEvent struct { - ID string + ID int64 + SourceEventID string SportID int32 MatchName string HomeTeam string @@ -79,7 +80,8 @@ type BaseEvent struct { FetchedAt time.Time } type BaseEventRes struct { - ID string `json:"id"` + ID int64 `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -107,7 +109,8 @@ type BaseEventRes struct { FetchedAt time.Time `json:"fetched_at"` } type EventWithSettings struct { - ID string + ID int64 + SourceEventID string SportID int32 MatchName string HomeTeam string @@ -140,7 +143,7 @@ type EventWithSettings struct { } type CreateEvent struct { - ID string + SourceEventID string SportID int32 MatchName string HomeTeam string @@ -159,7 +162,8 @@ type CreateEvent struct { } type EventWithSettingsRes struct { - ID string `json:"id"` + ID int64 `json:"id"` + SourceEventID string `json:"source_event_id"` SportID int32 `json:"sport_id"` MatchName string `json:"match_name"` HomeTeam string `json:"home_team"` @@ -193,7 +197,7 @@ type EventWithSettingsRes struct { type EventSettings struct { CompanyID int64 - EventID string + EventID int64 IsActive ValidBool IsFeatured ValidBool WinningUpperLimit ValidInt @@ -202,12 +206,36 @@ type EventSettings struct { type CreateEventSettings struct { CompanyID int64 - EventID string + EventID int64 IsActive ValidBool IsFeatured ValidBool WinningUpperLimit ValidInt } +type ValidEventStatus struct { + Value EventStatus + Valid bool +} + +func (v ValidEventStatus) ToPG() pgtype.Text { + return pgtype.Text{ + String: string(v.Value), + Valid: v.Valid, + } +} + +type ValidEventSource struct { + Value EventSource + Valid bool +} + +func (v ValidEventSource) ToPG() pgtype.Text { + return pgtype.Text{ + String: string(v.Value), + Valid: v.Valid, + } +} + type EventFilter struct { Query ValidString SportID ValidInt32 @@ -217,14 +245,17 @@ type EventFilter struct { LastStartTime ValidTime Limit ValidInt32 Offset ValidInt32 - MatchStatus ValidString // e.g., "upcoming", "in_play", "ended" Featured ValidBool Active ValidBool + IsLive ValidBool + Status ValidEventStatus + Source ValidEventSource } func ConvertDBEvent(event dbgen.EventWithCountry) BaseEvent { return BaseEvent{ ID: event.ID, + SourceEventID: event.SourceEventID, SportID: event.SportID, MatchName: event.MatchName, HomeTeam: event.HomeTeam, @@ -281,7 +312,7 @@ func ConvertDBEvents(events []dbgen.EventWithCountry) []BaseEvent { func ConvertCreateEvent(e CreateEvent) dbgen.InsertEventParams { return dbgen.InsertEventParams{ - ID: e.ID, + SourceEventID: e.SourceEventID, SportID: e.SportID, MatchName: e.MatchName, HomeTeam: e.HomeTeam, diff --git a/internal/domain/event_history.go b/internal/domain/event_history.go index 9a5460d..4574014 100644 --- a/internal/domain/event_history.go +++ b/internal/domain/event_history.go @@ -8,18 +8,18 @@ import ( type EventHistory struct { ID int64 - EventID string + EventID int64 Status string CreatedAt time.Time } type CreateEventHistory struct { - EventID string + EventID int64 Status string } type EventHistoryFilter struct { - EventID ValidString + EventID ValidInt64 CreatedBefore ValidTime CreatedAfter ValidTime } diff --git a/internal/domain/odds.go b/internal/domain/odds.go index 88092e1..2c94c78 100644 --- a/internal/domain/odds.go +++ b/internal/domain/odds.go @@ -9,22 +9,22 @@ import ( ) type CreateOddMarket struct { - EventID string + EventID int64 MarketCategory string MarketType string MarketName string - MarketID string + MarketID int64 UpdatedAt time.Time Odds []map[string]interface{} } type OddMarket struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` RawOdds []json.RawMessage `json:"raw_odds"` FetchedAt time.Time `json:"fetched_at"` ExpiresAt time.Time `json:"expires_at"` @@ -36,11 +36,11 @@ type OddMarket struct { } type OddMarketWithSettings struct { ID int64 `json:"id"` - EventID string `json:"event_id"` + EventID int64 `json:"event_id"` MarketType string `json:"market_type"` MarketName string `json:"market_name"` MarketCategory string `json:"market_category"` - MarketID string `json:"market_id"` + MarketID int64 `json:"market_id"` RawOdds []json.RawMessage `json:"raw_odds"` FetchedAt time.Time `json:"fetched_at"` ExpiresAt time.Time `json:"expires_at"` diff --git a/internal/domain/odds_history.go b/internal/domain/odds_history.go index 7413286..021ea5a 100644 --- a/internal/domain/odds_history.go +++ b/internal/domain/odds_history.go @@ -9,26 +9,26 @@ import ( type OddHistory struct { ID int64 OddID int64 - MarketID string + MarketID int64 RawOddID int64 - EventID string + EventID int64 OddValue float64 CreatedAt time.Time } type CreateOddHistory struct { OddID int64 - MarketID string + MarketID int64 RawOddID int64 - EventID string + EventID int64 OddValue float64 } type OddHistoryFilter struct { OddID ValidInt64 - MarketID ValidString + MarketID ValidInt64 RawOddID ValidInt64 - EventID ValidString + EventID ValidInt64 CreatedBefore ValidTime CreatedAfter ValidTime } diff --git a/internal/repository/event.go b/internal/repository/event.go index 8b4e87e..5458e6e 100644 --- a/internal/repository/event.go +++ b/internal/repository/event.go @@ -16,34 +16,13 @@ func (s *Store) SaveEvent(ctx context.Context, e domain.CreateEvent) error { return s.queries.InsertEvent(ctx, domain.ConvertCreateEvent(e)) } -func (s *Store) GetLiveEventIDs(ctx context.Context) ([]string, error) { +func (s *Store) GetLiveEventIDs(ctx context.Context) ([]int64, error) { return s.queries.ListLiveEvents(ctx) } -func (s *Store) GetAllUpcomingEvents(ctx context.Context) ([]domain.BaseEvent, error) { - events, err := s.queries.GetAllUpcomingEvents(ctx) - if err != nil { - return nil, err - } +func (s *Store) GetAllEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, int64, error) { - return domain.ConvertDBEvents(events), nil -} - -func (s *Store) GetExpiredUpcomingEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, error) { - events, err := s.queries.GetExpiredEvents(ctx, pgtype.Text{ - String: filter.MatchStatus.Value, - Valid: filter.MatchStatus.Valid, - }) - if err != nil { - return nil, err - } - - return domain.ConvertDBEvents(events), nil -} - -func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, int64, error) { - - events, err := s.queries.GetPaginatedUpcomingEvents(ctx, dbgen.GetPaginatedUpcomingEventsParams{ + events, err := s.queries.GetAllEvents(ctx, dbgen.GetAllEventsParams{ LeagueID: filter.LeagueID.ToPG(), SportID: filter.SportID.ToPG(), Query: filter.Query.ToPG(), @@ -52,6 +31,9 @@ func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, filter domain.Ev FirstStartTime: filter.FirstStartTime.ToPG(), LastStartTime: filter.LastStartTime.ToPG(), CountryCode: filter.CountryCode.ToPG(), + IsLive: filter.IsLive.ToPG(), + Status: filter.Status.ToPG(), + Source: filter.Source.ToPG(), }) if err != nil { @@ -65,6 +47,9 @@ func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, filter domain.Ev FirstStartTime: filter.FirstStartTime.ToPG(), LastStartTime: filter.LastStartTime.ToPG(), CountryCode: filter.CountryCode.ToPG(), + IsLive: filter.IsLive.ToPG(), + Status: filter.Status.ToPG(), + Source: filter.Source.ToPG(), }) if err != nil { return nil, 0, err @@ -87,6 +72,9 @@ func (s *Store) GetEventsWithSettings(ctx context.Context, companyID int64, filt CountryCode: filter.CountryCode.ToPG(), IsFeatured: filter.Featured.ToPG(), IsActive: filter.Active.ToPG(), + IsLive: filter.IsLive.ToPG(), + Status: filter.Status.ToPG(), + Source: filter.Source.ToPG(), }) if err != nil { @@ -103,6 +91,9 @@ func (s *Store) GetEventsWithSettings(ctx context.Context, companyID int64, filt CountryCode: filter.CountryCode.ToPG(), IsFeatured: filter.Featured.ToPG(), IsActive: filter.Active.ToPG(), + IsLive: filter.IsLive.ToPG(), + Status: filter.Status.ToPG(), + Source: filter.Source.ToPG(), }) if err != nil { return nil, 0, err @@ -166,15 +157,26 @@ func (s *Store) GetEventsWithSettings(ctx context.Context, companyID int64, filt return result, int64(numberOfPages), nil } -func (s *Store) GetUpcomingEventByID(ctx context.Context, ID string) (domain.BaseEvent, error) { - event, err := s.queries.GetUpcomingByID(ctx, ID) +func (s *Store) GetEventByID(ctx context.Context, ID int64) (domain.BaseEvent, error) { + event, err := s.queries.GetEventByID(ctx, ID) if err != nil { return domain.BaseEvent{}, err } return domain.ConvertDBEvent(event), nil } -func (s *Store) GetEventWithSettingByID(ctx context.Context, ID string, companyID int64) (domain.EventWithSettings, error) { +func (s *Store) GetEventBySourceID(ctx context.Context, id string, source domain.EventSource) (domain.BaseEvent, error) { + event, err := s.queries.GetEventBySourceID(ctx, dbgen.GetEventBySourceIDParams{ + SourceEventID: id, + Source: string(source), + }) + if err != nil { + return domain.BaseEvent{}, err + } + + return domain.ConvertDBEvent(event), nil +} +func (s *Store) GetEventWithSettingByID(ctx context.Context, ID int64, companyID int64) (domain.EventWithSettings, error) { event, err := s.queries.GetEventWithSettingByID(ctx, dbgen.GetEventWithSettingByIDParams{ ID: ID, CompanyID: companyID, @@ -234,7 +236,7 @@ func (s *Store) GetEventWithSettingByID(ctx context.Context, ID string, companyI } return res, nil } -func (s *Store) UpdateFinalScore(ctx context.Context, eventID, fullScore string, status domain.EventStatus) error { +func (s *Store) UpdateFinalScore(ctx context.Context, eventID int64, fullScore string, status domain.EventStatus) error { params := dbgen.UpdateMatchResultParams{ Score: pgtype.Text{String: fullScore, Valid: true}, Status: string(status), @@ -243,13 +245,13 @@ func (s *Store) UpdateFinalScore(ctx context.Context, eventID, fullScore string, err := s.queries.UpdateMatchResult(ctx, params) if err != nil { - return fmt.Errorf("failed to update final score for event %s: %w", eventID, err) + return fmt.Errorf("failed to update final score for event %v: %w", eventID, err) } return nil } -func (s *Store) UpdateEventStatus(ctx context.Context, eventID string, status domain.EventStatus) error { +func (s *Store) UpdateEventStatus(ctx context.Context, eventID int64, status domain.EventStatus) error { params := dbgen.UpdateMatchResultParams{ Status: string(status), ID: eventID, @@ -264,7 +266,7 @@ func (s *Store) UpdateEventStatus(ctx context.Context, eventID string, status do } -func (s *Store) IsEventMonitored(ctx context.Context, eventID string) (bool, error) { +func (s *Store) IsEventMonitored(ctx context.Context, eventID int64) (bool, error) { isMonitored, err := s.queries.IsEventMonitored(ctx, eventID) if err != nil { @@ -272,7 +274,7 @@ func (s *Store) IsEventMonitored(ctx context.Context, eventID string) (bool, err } return isMonitored, err } -func (s *Store) UpdateEventMonitored(ctx context.Context, eventID string, IsMonitored bool) error { +func (s *Store) UpdateEventMonitored(ctx context.Context, eventID int64, IsMonitored bool) error { return s.queries.UpdateEventMonitored(ctx, dbgen.UpdateEventMonitoredParams{ ID: eventID, IsMonitored: IsMonitored, @@ -283,7 +285,7 @@ func (s *Store) UpdateEventSettings(ctx context.Context, event domain.CreateEven return s.queries.SaveEventSettings(ctx, domain.ConvertUpdateEventSettings(event)) } -func (s *Store) DeleteEvent(ctx context.Context, eventID string) error { +func (s *Store) DeleteEvent(ctx context.Context, eventID int64) error { err := s.queries.DeleteEvent(ctx, eventID) if err != nil { return err diff --git a/internal/repository/odds.go b/internal/repository/odds.go index 3e09a91..51e1c6a 100644 --- a/internal/repository/odds.go +++ b/internal/repository/odds.go @@ -135,7 +135,7 @@ func (s *Store) GetOddByID(ctx context.Context, id int64) (domain.OddMarket, err return convertedOdd, nil } -func (s *Store) GetOddsByMarketID(ctx context.Context, marketID string, eventID string) (domain.OddMarket, error) { +func (s *Store) GetOddsByMarketID(ctx context.Context, marketID int64, eventID int64) (domain.OddMarket, error) { odds, err := s.queries.GetOddsByMarketID(ctx, dbgen.GetOddsByMarketIDParams{ MarketID: marketID, @@ -153,7 +153,7 @@ func (s *Store) GetOddsByMarketID(ctx context.Context, marketID string, eventID return convertedOdd, nil } -func (s *Store) GetOddsWithSettingsByMarketID(ctx context.Context, marketID string, eventID string, companyID int64) (domain.OddMarketWithSettings, error) { +func (s *Store) GetOddsWithSettingsByMarketID(ctx context.Context, marketID int64, eventID int64, companyID int64) (domain.OddMarketWithSettings, error) { odds, err := s.queries.GetOddsWithSettingsByMarketID(ctx, dbgen.GetOddsWithSettingsByMarketIDParams{ MarketID: marketID, @@ -236,9 +236,9 @@ func (s *Store) GetOddsWithSettingsByID(ctx context.Context, ID int64, companyID return converted, nil } -func (s *Store) GetOddsByEventID(ctx context.Context, upcomingID string, filter domain.OddMarketWithEventFilter) ([]domain.OddMarket, error) { +func (s *Store) GetOddsByEventID(ctx context.Context, eventID int64, filter domain.OddMarketWithEventFilter) ([]domain.OddMarket, error) { odds, err := s.queries.GetOddsByEventID(ctx, dbgen.GetOddsByEventIDParams{ - EventID: upcomingID, + EventID: eventID, Limit: filter.Limit.ToPG(), Offset: filter.Offset.ToPG(), IsLive: pgtype.Bool{ @@ -263,10 +263,10 @@ func (s *Store) GetOddsByEventID(ctx context.Context, upcomingID string, filter return domainOdds, nil } -func (s *Store) GetOddsWithSettingsByEventID(ctx context.Context, upcomingID string, companyID int64, filter domain.OddMarketFilter) ([]domain.OddMarketWithSettings, error) { +func (s *Store) GetOddsWithSettingsByEventID(ctx context.Context, eventID int64, companyID int64, filter domain.OddMarketFilter) ([]domain.OddMarketWithSettings, error) { odds, err := s.queries.GetOddsWithSettingsByEventID(ctx, dbgen.GetOddsWithSettingsByEventIDParams{ - EventID: upcomingID, + EventID: eventID, CompanyID: companyID, Offset: filter.Offset.ToPG(), Limit: filter.Limit.ToPG(), @@ -309,7 +309,7 @@ func (s *Store) GetOddsWithSettingsByEventID(ctx context.Context, upcomingID str return result, nil } -func (s *Store) DeleteOddsForEvent(ctx context.Context, eventID string) error { +func (s *Store) DeleteOddsForEvent(ctx context.Context, eventID int64) error { return s.queries.DeleteOddsForEvent(ctx, eventID) } diff --git a/internal/services/bet/service.go b/internal/services/bet/service.go index f101b07..4f869ed 100644 --- a/internal/services/bet/service.go +++ b/internal/services/bet/service.go @@ -106,11 +106,9 @@ func (s *Service) GenerateCashoutID() (string, error) { } func (s *Service) GenerateBetOutcome(ctx context.Context, eventID int64, marketID int64, oddID int64) (domain.CreateBetOutcome, error) { - eventIDStr := strconv.FormatInt(eventID, 10) - marketIDStr := strconv.FormatInt(marketID, 10) oddIDStr := strconv.FormatInt(oddID, 10) - event, err := s.eventSvc.GetUpcomingEventByID(ctx, eventIDStr) + event, err := s.eventSvc.GetEventByID(ctx, eventID) if err != nil { s.mongoLogger.Error("failed to fetch upcoming event by ID", zap.Int64("event_id", eventID), @@ -129,7 +127,7 @@ func (s *Service) GenerateBetOutcome(ctx context.Context, eventID int64, marketI return domain.CreateBetOutcome{}, ErrEventHasNotEnded } - odds, err := s.prematchSvc.GetOddsByMarketID(ctx, marketIDStr, eventIDStr) + odds, err := s.prematchSvc.GetOddsByMarketID(ctx, marketID, eventID) if err != nil { s.mongoLogger.Error("failed to get raw odds by market ID", zap.Int64("event_id", eventID), @@ -578,13 +576,13 @@ func (s *Service) DeductBetFromCustomerWallet(ctx context.Context, amount float3 return nil } -func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID string, sportID int32, HomeTeam, AwayTeam string, StartTime time.Time, numMarkets int) ([]domain.CreateBetOutcome, float32, error) { +func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID int64, sportID int32, HomeTeam, AwayTeam string, StartTime time.Time, numMarkets int) ([]domain.CreateBetOutcome, float32, error) { var newOdds []domain.CreateBetOutcome var totalOdds float32 = 1 eventLogger := s.mongoLogger.With( - zap.String("eventID", eventID), + zap.Int64("eventID", eventID), zap.Int32("sportID", sportID), zap.String("homeTeam", HomeTeam), zap.String("awayTeam", AwayTeam), @@ -638,12 +636,6 @@ func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID string, continue } - eventIDInt, err := strconv.ParseInt(eventID, 10, 64) - if err != nil { - eventLogger.Warn("Failed to parse eventID", zap.Error(err)) - continue - } - oddID, err := strconv.ParseInt(selectedOdd.ID, 10, 64) if err != nil { eventLogger.Warn("Failed to parse oddID", @@ -652,20 +644,12 @@ func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID string, continue } - marketID, err := strconv.ParseInt(market.MarketID, 10, 64) - if err != nil { - eventLogger.Warn("Failed to parse marketID", - zap.String("marketID", market.MarketID), - zap.Error(err)) - continue - } - marketName := market.MarketName newOdds = append(newOdds, domain.CreateBetOutcome{ - EventID: eventIDInt, + EventID: eventID, OddID: oddID, - MarketID: marketID, + MarketID: market.MarketID, SportID: int64(sportID), HomeTeamName: HomeTeam, AwayTeamName: AwayTeam, @@ -703,12 +687,15 @@ func (s *Service) PlaceRandomBet(ctx context.Context, userID, branchID, companyI zap.Any("firstStartTime", firstStartTime), zap.Any("lastStartTime", lastStartTime), ) - events, _, err := s.eventSvc.GetPaginatedUpcomingEvents(ctx, + events, _, err := s.eventSvc.GetAllEvents(ctx, domain.EventFilter{ SportID: sportID, LeagueID: leagueID, FirstStartTime: firstStartTime, LastStartTime: lastStartTime, + Status: domain.ValidEventStatus{ + Value: domain.STATUS_PENDING, + }, }) if err != nil { @@ -743,7 +730,7 @@ func (s *Service) PlaceRandomBet(ctx context.Context, userID, branchID, companyI newOdds, total, err := s.GenerateRandomBetOutcomes(ctx, event.ID, event.SportID, event.HomeTeam, event.AwayTeam, event.StartTime, numMarketsPerBet) if err != nil { - s.mongoLogger.Error("failed to generate random bet outcome", zap.String("eventID", event.ID), zap.Error(err)) + s.mongoLogger.Error("failed to generate random bet outcome", zap.Int64("eventID", event.ID), zap.Error(err)) continue } diff --git a/internal/services/event/port.go b/internal/services/event/port.go index 74305f9..faf2957 100644 --- a/internal/services/event/port.go +++ b/internal/services/event/port.go @@ -9,17 +9,15 @@ import ( type Service interface { // FetchLiveEvents(ctx context.Context) error FetchUpcomingEvents(ctx context.Context) error - GetAllUpcomingEvents(ctx context.Context) ([]domain.BaseEvent, error) - GetExpiredUpcomingEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, error) - GetPaginatedUpcomingEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, int64, error) - GetUpcomingEventByID(ctx context.Context, ID string) (domain.BaseEvent, error) - // GetAndStoreMatchResult(ctx context.Context, eventID string) error - UpdateFinalScore(ctx context.Context, eventID, fullScore string, status domain.EventStatus) error - UpdateEventStatus(ctx context.Context, eventID string, status domain.EventStatus) error - IsEventMonitored(ctx context.Context, eventID string) (bool, error) - UpdateEventMonitored(ctx context.Context, eventID string, IsMonitored bool) error + GetAllEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, int64, error) + GetEventByID(ctx context.Context, ID int64) (domain.BaseEvent, error) + // GetAndStoreMatchResult(ctx context.Context, eventID int64) error + UpdateFinalScore(ctx context.Context, eventID int64, fullScore string, status domain.EventStatus) error + UpdateEventStatus(ctx context.Context, eventID int64, status domain.EventStatus) error + IsEventMonitored(ctx context.Context, eventID int64) (bool, error) + UpdateEventMonitored(ctx context.Context, eventID int64, IsMonitored bool) error GetEventsWithSettings(ctx context.Context, companyID int64, filter domain.EventFilter) ([]domain.EventWithSettings, int64, error) - GetEventWithSettingByID(ctx context.Context, ID string, companyID int64) (domain.EventWithSettings, error) + GetEventWithSettingByID(ctx context.Context, ID int64, companyID int64) (domain.EventWithSettings, error) UpdateEventSettings(ctx context.Context, event domain.CreateEventSettings) error GetSportAndLeagueIDs(ctx context.Context, eventID string) ([]int64, error) } diff --git a/internal/services/event/service.go b/internal/services/event/service.go index 4f56c2a..b61391c 100644 --- a/internal/services/event/service.go +++ b/internal/services/event/service.go @@ -16,7 +16,6 @@ import ( "github.com/SamuelTariku/FortuneBet-Backend/internal/domain" "github.com/SamuelTariku/FortuneBet-Backend/internal/repository" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/settings" - "github.com/jackc/pgx/v5" "go.uber.org/zap" // "github.com/SamuelTariku/FortuneBet-Backend/internal/services/event" ) @@ -325,7 +324,7 @@ func (s *service) fetchUpcomingEventsFromProvider(ctx context.Context, source_ur // } event := domain.CreateEvent{ - ID: ev.ID, + SourceEventID: ev.ID, SportID: convertInt32(ev.SportID), HomeTeam: ev.Home.Name, AwayTeam: "", // handle nil safely @@ -392,38 +391,30 @@ func (s *service) fetchUpcomingEventsFromProvider(ctx context.Context, source_ur ) } -func (s *service) CheckAndInsertEventHistory(ctx context.Context, event domain.CreateEvent) (bool, error) { - isEventMonitored, err := s.store.IsEventMonitored(ctx, event.ID) +func (s *service) CheckAndInsertEventHistory(ctx context.Context, newEvent domain.CreateEvent) (bool, error) { eventLogger := s.mongoLogger.With( - zap.String("eventID", event.ID), - zap.Int64("leagueID", event.LeagueID), - zap.String("leagueName", event.LeagueName), - zap.Int32("sport_id", event.SportID), + zap.String("sourceEventID", newEvent.SourceEventID), + zap.String("source", string(newEvent.Source)), + zap.Int64("leagueID", newEvent.LeagueID), + zap.String("leagueName", newEvent.LeagueName), + zap.Int32("sport_id", newEvent.SportID), ) + oldEvent, err := s.store.GetEventBySourceID(ctx, newEvent.SourceEventID, newEvent.Source) + if err != nil { - if err != pgx.ErrNoRows { - eventLogger.Info("failed to get event is_monitored", zap.Error(err)) - } return false, err } - if !isEventMonitored { + if !oldEvent.IsMonitored { return false, nil } - oldEvent, err := s.GetUpcomingEventByID(ctx, event.ID) - - if err != nil { - eventLogger.Error("failed to get event by id", zap.Error(err)) - return false, err - } - - if oldEvent.Status != event.Status { + if oldEvent.Status != newEvent.Status { _, err := s.store.InsertEventHistory(ctx, domain.CreateEventHistory{ - EventID: event.ID, - Status: string(event.Status), + EventID: oldEvent.ID, + Status: string(newEvent.Status), }) if err != nil { @@ -470,34 +461,26 @@ func convertInt64(num string) int64 { } return 0 } -func (s *service) GetAllUpcomingEvents(ctx context.Context) ([]domain.BaseEvent, error) { - return s.store.GetAllUpcomingEvents(ctx) +func (s *service) GetAllEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, int64, error) { + return s.store.GetAllEvents(ctx, filter) } -func (s *service) GetExpiredUpcomingEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, error) { - return s.store.GetExpiredUpcomingEvents(ctx, filter) + +func (s *service) GetEventByID(ctx context.Context, ID int64) (domain.BaseEvent, error) { + return s.store.GetEventByID(ctx, ID) } -func (s *service) GetPaginatedUpcomingEvents(ctx context.Context, filter domain.EventFilter) ([]domain.BaseEvent, int64, error) { - return s.store.GetPaginatedUpcomingEvents(ctx, filter) -} - -func (s *service) GetUpcomingEventByID(ctx context.Context, ID string) (domain.BaseEvent, error) { - return s.store.GetUpcomingEventByID(ctx, ID) -} - -func (s *service) UpdateFinalScore(ctx context.Context, eventID, fullScore string, status domain.EventStatus) error { +func (s *service) UpdateFinalScore(ctx context.Context, eventID int64, fullScore string, status domain.EventStatus) error { return s.store.UpdateFinalScore(ctx, eventID, fullScore, status) } - -func (s *service) UpdateEventStatus(ctx context.Context, eventID string, status domain.EventStatus) error { +func (s *service) UpdateEventStatus(ctx context.Context, eventID int64, status domain.EventStatus) error { return s.store.UpdateEventStatus(ctx, eventID, status) } -func (s *service) IsEventMonitored(ctx context.Context, eventID string) (bool, error) { +func (s *service) IsEventMonitored(ctx context.Context, eventID int64) (bool, error) { return s.store.IsEventMonitored(ctx, eventID) } -func (s *service) UpdateEventMonitored(ctx context.Context, eventID string, IsMonitored bool) error { +func (s *service) UpdateEventMonitored(ctx context.Context, eventID int64, IsMonitored bool) error { return s.store.UpdateEventMonitored(ctx, eventID, IsMonitored) } @@ -505,7 +488,7 @@ func (s *service) GetEventsWithSettings(ctx context.Context, companyID int64, fi return s.store.GetEventsWithSettings(ctx, companyID, filter) } -func (s *service) GetEventWithSettingByID(ctx context.Context, ID string, companyID int64) (domain.EventWithSettings, error) { +func (s *service) GetEventWithSettingByID(ctx context.Context, ID int64, companyID int64) (domain.EventWithSettings, error) { return s.store.GetEventWithSettingByID(ctx, ID, companyID) } diff --git a/internal/services/odds/service.go b/internal/services/odds/service.go index b52bf0e..fcbabb3 100644 --- a/internal/services/odds/service.go +++ b/internal/services/odds/service.go @@ -49,8 +49,8 @@ func (s *ServiceImpl) FetchNonLiveOdds(ctx context.Context) error { go func() { defer wg.Done() - if err := s.fetchBet365Odds(ctx); err != nil { - errChan <- fmt.Errorf("bet365 odds fetching error: %w", err) + if err := s.ProcessBet365Odds(ctx); err != nil { + errChan <- fmt.Errorf("failed while processing bet365 odds error: %w", err) } }() @@ -78,8 +78,20 @@ func (s *ServiceImpl) FetchNonLiveOdds(ctx context.Context) error { return nil } -func (s *ServiceImpl) fetchBet365Odds(ctx context.Context) error { - eventIDs, err := s.eventSvc.GetAllUpcomingEvents(ctx) +func (s *ServiceImpl) ProcessBet365Odds(ctx context.Context) error { + eventIDs, _, err := s.eventSvc.GetAllEvents(ctx, domain.EventFilter{ + LastStartTime: domain.ValidTime{ + Value: time.Now(), + Valid: true, + }, + Status: domain.ValidEventStatus{ + Value: domain.STATUS_PENDING, + Valid: true, + }, + Source: domain.ValidEventSource{ + Value: domain.EVENT_SOURCE_BET365, + }, + }) if err != nil { s.mongoLogger.Error( "Failed to fetch upcoming event IDs", @@ -94,10 +106,10 @@ func (s *ServiceImpl) fetchBet365Odds(ctx context.Context) error { } eventLogger := s.mongoLogger.With( - zap.String("eventID", event.ID), + zap.Int64("eventID", event.ID), zap.Int32("sportID", event.SportID), ) - oddsData, err := s.FetchNonLiveOddsByEventID(ctx, event.ID) + oddsData, err := s.FetchB365Odds(ctx, event.SourceEventID) if err != nil || oddsData.Success != 1 { eventLogger.Error("Failed to fetch prematch odds", zap.Error(err)) continue @@ -254,26 +266,15 @@ func (s *ServiceImpl) fetchBet365Odds(ctx context.Context) error { // return nil // } -func (s *ServiceImpl) FetchNonLiveOddsByEventID(ctx context.Context, eventIDStr string) (domain.BaseNonLiveOddResponse, error) { +func (s *ServiceImpl) FetchB365Odds(ctx context.Context, eventID string) (domain.BaseNonLiveOddResponse, error) { - eventID, err := strconv.ParseInt(eventIDStr, 10, 64) - if err != nil { - s.logger.Error("Failed to parse event id") - s.mongoLogger.Error( - "Failed to parse event id", - zap.String("eventID", eventIDStr), - zap.Error(err), - ) - return domain.BaseNonLiveOddResponse{}, err - } - - url := fmt.Sprintf("https://api.b365api.com/v3/bet365/prematch?token=%s&FI=%d", s.config.Bet365Token, eventID) + url := fmt.Sprintf("https://api.b365api.com/v3/bet365/prematch?token=%s&FI=%v", s.config.Bet365Token, eventID) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { s.mongoLogger.Error( "Failed to create request for event", - zap.String("eventID", eventIDStr), + zap.String("eventID", eventID), zap.Error(err), ) @@ -283,7 +284,7 @@ func (s *ServiceImpl) FetchNonLiveOddsByEventID(ctx context.Context, eventIDStr if err != nil { s.mongoLogger.Error( "Failed to fetch prematch odds for event", - zap.String("eventID", eventIDStr), + zap.String("eventID", eventID), zap.Error(err), ) return domain.BaseNonLiveOddResponse{}, err @@ -294,7 +295,7 @@ func (s *ServiceImpl) FetchNonLiveOddsByEventID(ctx context.Context, eventIDStr if err != nil { s.mongoLogger.Error( "Failed to read response body for event", - zap.String("eventID", eventIDStr), + zap.String("eventID", eventID), zap.Error(err), ) return domain.BaseNonLiveOddResponse{}, err @@ -304,7 +305,8 @@ func (s *ServiceImpl) FetchNonLiveOddsByEventID(ctx context.Context, eventIDStr if err := json.Unmarshal(body, &oddsData); err != nil || oddsData.Success != 1 || len(oddsData.Results) == 0 { s.mongoLogger.Error( "Invalid prematch data for event", - zap.String("eventID", eventIDStr), + zap.String("eventID", eventID), + zap.Error(err), ) return domain.BaseNonLiveOddResponse{}, err @@ -511,10 +513,11 @@ func (s *ServiceImpl) ParseOddSections(ctx context.Context, res json.RawMessage, }, nil } -func (s *ServiceImpl) storeSection(ctx context.Context, eventID, fi, sectionName string, section domain.OddsSection) error { +func (s *ServiceImpl) storeSection(ctx context.Context, eventID int64, fi, sectionName string, section domain.OddsSection) error { + if len(section.Sp) == 0 { s.mongoLogger.Warn("Event Section is empty", - zap.String("eventID", eventID), + zap.Int64("eventID", eventID), zap.String("sectionName", sectionName), ) return nil @@ -526,7 +529,7 @@ func (s *ServiceImpl) storeSection(ctx context.Context, eventID, fi, sectionName var errs []error for marketType, market := range section.Sp { marketLogger := s.mongoLogger.With( - zap.String("eventID", eventID), + zap.Int64("eventID", eventID), zap.String("sectionName", sectionName), zap.String("market_id", string(market.ID)), zap.String("marketType", marketType), @@ -543,8 +546,6 @@ func (s *ServiceImpl) storeSection(ctx context.Context, eventID, fi, sectionName continue } - marketIDstr := strconv.FormatInt(marketIDint, 10) - isSupported, ok := domain.SupportedMarkets[marketIDint] if !ok || !isSupported { @@ -564,7 +565,7 @@ func (s *ServiceImpl) storeSection(ctx context.Context, eventID, fi, sectionName MarketCategory: sectionName, MarketType: marketType, MarketName: market.Name, - MarketID: marketIDstr, + MarketID: marketIDint, UpdatedAt: updatedAt, Odds: marketOdds, // bwin won't reach this code so bet365 is hardcoded for now @@ -593,9 +594,9 @@ func (s *ServiceImpl) CheckAndInsertOddHistory(ctx context.Context, market domai isEventMonitored, err := s.eventSvc.IsEventMonitored(ctx, market.EventID) marketLogger := s.mongoLogger.With( - zap.String("market_id", market.MarketID), + zap.Int64("market_id", market.MarketID), zap.String("market_name", market.MarketName), - zap.String("eventID", market.EventID), + zap.Int64("eventID", market.EventID), ) if err != nil { marketLogger.Error("failed to get is_monitored", zap.Error(err)) @@ -644,9 +645,9 @@ func (s *ServiceImpl) CheckAndInsertOddHistory(ctx context.Context, market domai if err != nil { s.mongoLogger.Error( "failed to insert odd history", - zap.String("market_id", market.MarketID), + zap.Int64("market_id", market.MarketID), zap.String("market_name", market.MarketName), - zap.String("eventID", market.EventID), + zap.Int64("eventID", market.EventID), zap.Int64("odd_id", oldOdds.ID), zap.Int("raw_odd_id", newRawOddID), zap.Error(err), @@ -711,7 +712,7 @@ func (s *ServiceImpl) SaveOddsSettingReq(ctx context.Context, companyID int64, r }) } -func (s *ServiceImpl) GetOddsByMarketID(ctx context.Context, marketID string, eventID string) (domain.OddMarket, error) { +func (s *ServiceImpl) GetOddsByMarketID(ctx context.Context, marketID int64, eventID int64) (domain.OddMarket, error) { rows, err := s.store.GetOddsByMarketID(ctx, marketID, eventID) if err != nil { return domain.OddMarket{}, err @@ -719,7 +720,7 @@ func (s *ServiceImpl) GetOddsByMarketID(ctx context.Context, marketID string, ev return rows, nil } -func (s *ServiceImpl) GetOddsWithSettingsByMarketID(ctx context.Context, marketID string, eventID string, companyID int64) (domain.OddMarketWithSettings, error) { +func (s *ServiceImpl) GetOddsWithSettingsByMarketID(ctx context.Context, marketID int64, eventID int64, companyID int64) (domain.OddMarketWithSettings, error) { rows, err := s.store.GetOddsWithSettingsByMarketID(ctx, marketID, eventID, companyID) if err != nil { return domain.OddMarketWithSettings{}, err @@ -732,15 +733,15 @@ func (s *ServiceImpl) GetOddsWithSettingsByID(ctx context.Context, ID int64, com return s.store.GetOddsWithSettingsByID(ctx, ID, companyID) } -func (s *ServiceImpl) GetOddsByEventID(ctx context.Context, upcomingID string, filter domain.OddMarketWithEventFilter) ([]domain.OddMarket, error) { - return s.store.GetOddsByEventID(ctx, upcomingID, filter) +func (s *ServiceImpl) GetOddsByEventID(ctx context.Context, eventID int64, filter domain.OddMarketWithEventFilter) ([]domain.OddMarket, error) { + return s.store.GetOddsByEventID(ctx, eventID, filter) } -func (s *ServiceImpl) GetOddsWithSettingsByEventID(ctx context.Context, upcomingID string, companyID int64, filter domain.OddMarketFilter) ([]domain.OddMarketWithSettings, error) { - return s.store.GetOddsWithSettingsByEventID(ctx, upcomingID, companyID, filter) +func (s *ServiceImpl) GetOddsWithSettingsByEventID(ctx context.Context, eventID int64, companyID int64, filter domain.OddMarketFilter) ([]domain.OddMarketWithSettings, error) { + return s.store.GetOddsWithSettingsByEventID(ctx, eventID, companyID, filter) } -func (s *ServiceImpl) DeleteOddsForEvent(ctx context.Context, eventID string) error { +func (s *ServiceImpl) DeleteOddsForEvent(ctx context.Context, eventID int64) error { return s.store.DeleteOddsForEvent(ctx, eventID) } diff --git a/internal/services/result/service.go b/internal/services/result/service.go index 245ff89..48cebb0 100644 --- a/internal/services/result/service.go +++ b/internal/services/result/service.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "log" "log/slog" "net/http" "strconv" @@ -98,7 +99,7 @@ func (s *Service) UpdateResultForOutcomes(ctx context.Context, eventID int64, re continue } - parseResult, err := s.parseResult(resultRes, outcome, sportID) + parseResult, err := s.ParseB365Result(resultRes, outcome, sportID) if err != nil { outcomeLogger.Error("Failed to parse result", zap.Error(err)) @@ -111,7 +112,7 @@ func (s *Service) UpdateResultForOutcomes(ctx context.Context, eventID int64, re } if outcome.Status == domain.OUTCOME_STATUS_ERROR || outcome.Status == domain.OUTCOME_STATUS_PENDING { outcomeLogger.Error("Outcome has been updated to pending or error", zap.Error(err)) - // return fmt.Errorf("Error while updating outcome") + // return fmt.Errorf("error while updating outcome") continue } @@ -227,10 +228,20 @@ func (s *Service) RefundAllOutcomes(ctx context.Context, eventID int64) (map[int } -func (s *Service) FetchAndProcessResults(ctx context.Context) error { +func (s *Service) FetchB365ResultAndUpdateBets(ctx context.Context) error { // TODO: Optimize this because there could be many bet outcomes for the same odd // Take market id and match result as param and update all the bet outcomes at the same time - events, err := s.repo.GetExpiredUpcomingEvents(ctx, domain.EventFilter{}) + events, _, err := s.repo.GetAllEvents(ctx, domain.EventFilter{ + LastStartTime: domain.ValidTime{ + Value: time.Now(), + Valid: true, + }, + Source: domain.ValidEventSource{ + Value: domain.EVENT_SOURCE_BET365, + Valid: true, + }, + }) + if err != nil { s.logger.Error("Failed to fetch events") s.mongoLogger.Error( @@ -243,17 +254,16 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { empty_sport_id := make([]int64, 0) var resultLog domain.CreateResultLog var resultStatusBets domain.ResultStatusBets - for _, event := range events { - eventLogger := s.mongoLogger.With( - zap.String("eventID", event.ID), - ) - eventID, err := strconv.ParseInt(event.ID, 10, 64) - if err != nil { - eventLogger.Error("Failed to parse Event ID", zap.Error(err)) - continue + for i, event := range events { + if s.config.Env == "development" { + log.Printf("⚙️ Processing Bets For Event %v (%d/%d) \n", event.ID, i+1, len(events)) } - result, err := s.fetchResult(ctx, eventID) + eventLogger := s.mongoLogger.With( + zap.Int64("eventID", event.ID), + ) + + result, err := s.FetchB365Result(ctx, event.SourceEventID) if err != nil { if err == ErrEventIsNotActive { eventLogger.Warn("Event is not active", zap.Error(err)) @@ -294,7 +304,7 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { switch timeStatusParsed { case int64(domain.TIME_STATUS_NOT_STARTED), int64(domain.TIME_STATUS_IN_PLAY): resultLog.StatusNotFinishedCount += 1 - bets, err := s.GetTotalBetsForEvents(ctx, eventID) + bets, err := s.GetTotalBetsForEvents(ctx, event.ID) if err != nil { continue } @@ -304,8 +314,11 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { } case int64(domain.TIME_STATUS_TO_BE_FIXED): - totalBetsRefunded, err := s.RefundAllOutcomes(ctx, eventID) - + totalBetsRefunded, err := s.RefundAllOutcomes(ctx, event.ID) + if err != nil { + commonRespLogger.Error("Failed to refund all outcomes", zap.Error(err)) + continue + } err = s.repo.DeleteEvent(ctx, event.ID) if err != nil { commonRespLogger.Error("Failed to remove event", zap.Error(err)) @@ -329,7 +342,7 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { // ) case int64(domain.TIME_STATUS_POSTPONED), int64(domain.TIME_STATUS_SUSPENDED): - bets, err := s.GetTotalBetsForEvents(ctx, eventID) + bets, err := s.GetTotalBetsForEvents(ctx, event.ID) if err != nil { continue } @@ -346,7 +359,7 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { // ) case int64(domain.TIME_STATUS_ENDED), int64(domain.TIME_STATUS_WALKOVER), int64(domain.TIME_STATUS_DECIDED_BY_FA): if commonResp.SportID == "" { - empty_sport_id = append(empty_sport_id, eventID) + empty_sport_id = append(empty_sport_id, event.ID) continue } sportID, err := strconv.ParseInt(commonResp.SportID, 10, 64) @@ -354,7 +367,7 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { commonRespLogger.Error("Failed to parse sport id", zap.Error(err)) continue } - err = s.UpdateResultForOutcomes(ctx, eventID, result.Results[0], sportID) + err = s.UpdateResultForOutcomes(ctx, event.ID, result.Results[0], sportID) if err != nil { commonRespLogger.Error("Error while updating result for event", zap.Error(err)) } @@ -370,7 +383,7 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { } resultLog.RemovedCount += 1 resultLog.StatusEndedCount += 1 - bets, err := s.GetTotalBetsForEvents(ctx, eventID) + bets, err := s.GetTotalBetsForEvents(ctx, event.ID) if err != nil { continue } @@ -390,7 +403,10 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error { // zap.Int64("eventID", eventID), // zap.Int64("status", timeStatusParsed), // ) - totalBetsRefunded, err := s.RefundAllOutcomes(ctx, eventID) + totalBetsRefunded, err := s.RefundAllOutcomes(ctx, event.ID) + if err != nil { + commonRespLogger.Error("Failed to refund outcomes", zap.Error(err)) + } err = s.repo.DeleteEvent(ctx, event.ID) if err != nil { @@ -711,8 +727,17 @@ func (s *Service) SendAdminResultStatusErrorNotification( return nil } -func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error) { - events, err := s.repo.GetExpiredUpcomingEvents(ctx, domain.EventFilter{}) +func (s *Service) CheckAndUpdateExpiredB365Events(ctx context.Context) (int64, error) { + events, _, err := s.repo.GetAllEvents(ctx, domain.EventFilter{ + LastStartTime: domain.ValidTime{ + Value: time.Now(), + Valid: true, + }, + Source: domain.ValidEventSource{ + Value: domain.EVENT_SOURCE_BET365, + Valid: true, + }, + }) if err != nil { s.mongoLogger.Error( "Failed to fetch events", @@ -724,27 +749,20 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error updated := 0 var leagueCountries []string eventResultStats := make(map[string]int) - for _, event := range events { - // fmt.Printf("⚙️ Processing event %v (%d/%d) \n", event.ID, i+1, len(events)) - eventID, err := strconv.ParseInt(event.ID, 10, 64) - if err != nil { - s.mongoLogger.Error( - "Failed to parse event id", - zap.String("eventID", event.ID), - zap.Error(err), - ) - continue + for i, event := range events { + if s.config.Env == "development" { + log.Printf("⚙️ Checking and Updating Status for Event %v (%d/%d) \n", event.ID, i+1, len(events)) } if event.Status == domain.STATUS_REMOVED { skipped += 1 continue } - result, err := s.fetchResult(ctx, eventID) + result, err := s.FetchB365Result(ctx, event.SourceEventID) if err != nil { s.mongoLogger.Error( "Failed to fetch result", - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), zap.Error(err), ) continue @@ -752,7 +770,7 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error if result.Success != 1 || len(result.Results) == 0 { s.mongoLogger.Error( "Invalid API result response", - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), zap.Error(err), ) continue @@ -763,7 +781,7 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error fmt.Printf("UnMarshalling error %v \n", err) s.mongoLogger.Error( "Failed to unmarshal common result", - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), zap.Error(err), ) continue @@ -823,16 +841,16 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error s.mongoLogger.Error( "Invalid time status", zap.Int64("time_status", timeStatus), - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), ) continue } - err = s.eventSvc.UpdateFinalScore(ctx, strconv.FormatInt(eventID, 10), commonResp.SS, eventStatus) + err = s.eventSvc.UpdateFinalScore(ctx, event.ID, commonResp.SS, eventStatus) if err != nil { s.mongoLogger.Error( "Failed to update final score", - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), zap.String("SS", commonResp.SS), zap.String("eventStatus", string(eventStatus)), zap.Error(err), @@ -852,7 +870,7 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error if commonResp.League.ID == "" { s.mongoLogger.Warn( "League ID empty on result response", - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), zap.String("leagueID", commonResp.League.ID), ) continue @@ -861,7 +879,7 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error if err != nil { s.mongoLogger.Error( "Invalid League ID", - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), zap.Error(err), ) continue @@ -883,7 +901,7 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error s.mongoLogger.Error( "Error Updating League", zap.String("League Name", commonResp.League.Name), - zap.Int64("eventID", eventID), + zap.Int64("eventID", event.ID), zap.Error(err), ) continue @@ -919,22 +937,14 @@ func (s *Service) CheckAndUpdateExpiredEvents(ctx context.Context) (int64, error } -func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json.RawMessage, []domain.BetOutcome, error) { - id, err := strconv.ParseInt(eventID, 10, 64) - if err != nil { - s.mongoLogger.Error( - "Failed to parse event id", - zap.String("eventID", eventID), - zap.Error(err), - ) - return json.RawMessage{}, nil, err - } +// Gets a B365 Result and returns the outcomes that this result would give +func (s *Service) GetBet365ResultForEvent(ctx context.Context, b365EventID string) (json.RawMessage, []domain.BetOutcome, error) { - result, err := s.fetchResult(ctx, id) + result, err := s.FetchB365Result(ctx, b365EventID) if err != nil { s.mongoLogger.Error( "Failed to fetch result", - zap.Int64("eventID", id), + zap.String("b365EventID", b365EventID), zap.Error(err), ) } @@ -942,17 +952,17 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. s.mongoLogger.Error( "Invalid API result response", zap.Any("result", result), - zap.Int64("eventID", id), + zap.String("b365EventID", b365EventID), zap.Error(err), ) - return json.RawMessage{}, nil, fmt.Errorf("invalid API response for event %d", id) + return json.RawMessage{}, nil, fmt.Errorf("invalid API response for event %d", b365EventID) } var commonResp domain.CommonResultResponse if err := json.Unmarshal(result.Results[0], &commonResp); err != nil { s.mongoLogger.Error( "Failed to unmarshal common result", - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) return json.RawMessage{}, nil, err @@ -960,16 +970,16 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. if commonResp.SportID == "" { s.mongoLogger.Warn( "Sport ID is empty", - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), ) - return json.RawMessage{}, nil, fmt.Errorf("sport id empty for event: %v", eventID) + return json.RawMessage{}, nil, fmt.Errorf("sport id empty for event: %v", b365EventID) } sportID, err := strconv.ParseInt(commonResp.SportID, 10, 32) if err != nil { s.mongoLogger.Error( "Failed to parse sport id", zap.String("sportID", commonResp.SportID), - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) return json.RawMessage{}, nil, fmt.Errorf("failed to parse sport id: %w", err) @@ -979,22 +989,22 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. if err != nil { s.mongoLogger.Error( "Failed to parse expire time", - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) - return json.RawMessage{}, nil, fmt.Errorf("Failed to parse expire time for event %s: %w", eventID, err) + return json.RawMessage{}, nil, fmt.Errorf("failed to parse expire time for event %s: %w", b365EventID, err) } expires := time.Unix(expireUnix, 0) - odds, err := s.oddSvc.FetchNonLiveOddsByEventID(ctx, eventID) + odds, err := s.oddSvc.FetchB365Odds(ctx, b365EventID) if err != nil { s.mongoLogger.Error( "Failed to fetch non-live odds by event ID", - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) - return json.RawMessage{}, nil, fmt.Errorf("failed to fetch non-live odds for event %s: %w", eventID, err) + return json.RawMessage{}, nil, fmt.Errorf("failed to fetch non-live odds for event %s: %w", b365EventID, err) } parsedOddSections, err := s.oddSvc.ParseOddSections(ctx, odds.Results[0], int32(sportID)) @@ -1002,10 +1012,10 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. s.mongoLogger.Error( "Failed to parse odd section", zap.Int64("sportID", sportID), - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) - return json.RawMessage{}, nil, fmt.Errorf("failed to parse odd section for event %v: %w", eventID, err) + return json.RawMessage{}, nil, fmt.Errorf("failed to parse odd section for event %v: %w", b365EventID, err) } outcomes := make([]domain.BetOutcome, 0) @@ -1017,7 +1027,7 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. "Invalid market id", zap.Int64("market_id", marketIDint), zap.String("market_name", market.Name), - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) continue @@ -1072,7 +1082,6 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. } outcome := domain.BetOutcome{ - EventID: id, MarketID: marketIDint, OddID: oddID, MarketName: market.Name, @@ -1097,20 +1106,21 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. if len(outcomes) == 0 { s.mongoLogger.Warn( "No outcomes found for event", - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), ) - return json.RawMessage{}, nil, fmt.Errorf("no outcomes found for event %s", eventID) + return json.RawMessage{}, nil, fmt.Errorf("no outcomes found for event %v", b365EventID) } + s.mongoLogger.Info( "Successfully fetched outcomes for event", - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Int("outcomes", len(outcomes)), ) // Get results for outcome for i, outcome := range outcomes { // Parse the result based on sport type - parsedResult, err := s.parseResult(result.Results[0], outcome, sportID) + parsedResult, err := s.ParseB365Result(result.Results[0], outcome, sportID) if err != nil { s.mongoLogger.Error( "Failed to parse result for outcome", @@ -1127,15 +1137,16 @@ func (s *Service) GetResultsForEvent(ctx context.Context, eventID string) (json. return result.Results[0], outcomes, err } -func (s *Service) fetchResult(ctx context.Context, eventID int64) (domain.BaseResultResponse, error) { - url := fmt.Sprintf("https://api.b365api.com/v1/bet365/result?token=%s&event_id=%d", s.config.Bet365Token, eventID) +// Fetch B365 Base Result +func (s *Service) FetchB365Result(ctx context.Context, b365EventID string) (domain.BaseResultResponse, error) { + url := fmt.Sprintf("https://api.b365api.com/v1/bet365/result?token=%s&event_id=%v", s.config.Bet365Token, b365EventID) // url := fmt.Sprintf("https://api.b365api.com/v1/event/view?token=%s&event_id=%d", s.config.Bet365Token, eventID) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { s.mongoLogger.Error( "Failed to create request", - zap.Int64("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) return domain.BaseResultResponse{}, err @@ -1145,7 +1156,7 @@ func (s *Service) fetchResult(ctx context.Context, eventID int64) (domain.BaseRe if err != nil { s.mongoLogger.Error( "Failed to get fetch result response", - zap.Int64("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) return domain.BaseResultResponse{}, err @@ -1155,7 +1166,7 @@ func (s *Service) fetchResult(ctx context.Context, eventID int64) (domain.BaseRe if resp.StatusCode != http.StatusOK { s.mongoLogger.Error( "Unexpected status code", - zap.Int64("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Int("status_code", resp.StatusCode), zap.Error(err), ) @@ -1166,7 +1177,7 @@ func (s *Service) fetchResult(ctx context.Context, eventID int64) (domain.BaseRe if err := json.NewDecoder(resp.Body).Decode(&resultResp); err != nil { s.mongoLogger.Error( "Failed to decode result", - zap.Int64("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) return domain.BaseResultResponse{}, err @@ -1175,7 +1186,7 @@ func (s *Service) fetchResult(ctx context.Context, eventID int64) (domain.BaseRe if resultResp.Success != 1 || len(resultResp.Results) == 0 { s.mongoLogger.Error( "Invalid API response", - zap.Int64("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Error(err), ) return domain.BaseResultResponse{}, fmt.Errorf("invalid API response") @@ -1184,7 +1195,7 @@ func (s *Service) fetchResult(ctx context.Context, eventID int64) (domain.BaseRe return resultResp, nil } -func (s *Service) parseResult(resultResp json.RawMessage, outcome domain.BetOutcome, sportID int64) (domain.CreateResult, error) { +func (s *Service) ParseB365Result(resultResp json.RawMessage, outcome domain.BetOutcome, sportID int64) (domain.CreateResult, error) { var result domain.CreateResult var err error diff --git a/internal/services/ticket/service.go b/internal/services/ticket/service.go index 3514960..c09475d 100644 --- a/internal/services/ticket/service.go +++ b/internal/services/ticket/service.go @@ -57,10 +57,8 @@ func NewService( } func (s *Service) GenerateTicketOutcome(ctx context.Context, settings domain.SettingList, eventID int64, marketID int64, oddID int64) (domain.CreateTicketOutcome, error) { - eventIDStr := strconv.FormatInt(eventID, 10) - marketIDStr := strconv.FormatInt(marketID, 10) oddIDStr := strconv.FormatInt(oddID, 10) - event, err := s.eventSvc.GetUpcomingEventByID(ctx, eventIDStr) + event, err := s.eventSvc.GetEventByID(ctx, eventID) if err != nil { s.mongoLogger.Error("failed to fetch upcoming event by ID", zap.Int64("event_id", eventID), @@ -80,7 +78,7 @@ func (s *Service) GenerateTicketOutcome(ctx context.Context, settings domain.Set return domain.CreateTicketOutcome{}, ErrTicketHasExpired } - odds, err := s.prematchSvc.GetOddsByMarketID(ctx, marketIDStr, eventIDStr) + odds, err := s.prematchSvc.GetOddsByMarketID(ctx, marketID, eventID) if err != nil { s.mongoLogger.Error("failed to get raw odds by market ID", diff --git a/internal/web_server/cron.go b/internal/web_server/cron.go index 3c39dfc..2e5c8dc 100644 --- a/internal/web_server/cron.go +++ b/internal/web_server/cron.go @@ -56,7 +56,7 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S // spec: "0 */5 * * * *", // Every 5 Minutes // task: func() { // mongoLogger.Info("Began update all expired events status cron task") - // if _, err := resultService.CheckAndUpdateExpiredEvents(context.Background()); err != nil { + // if _, err := resultService.CheckAndUpdateExpiredB365Events(context.Background()); err != nil { // mongoLogger.Error("Failed to update expired events status", // zap.Error(err), // ) @@ -68,8 +68,8 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S // { // spec: "0 */15 * * * *", // Every 15 Minutes // task: func() { - // mongoLogger.Info("Began fetching results for upcoming events cron task") - // if err := resultService.FetchAndProcessResults(context.Background()); err != nil { + // mongoLogger.Info("Began updating bets based on event results cron task") + // if err := resultService.FetchB365ResultAndUpdateBets(context.Background()); err != nil { // mongoLogger.Error("Failed to process result", // zap.Error(err), // ) @@ -78,23 +78,23 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S // } // }, // }, - // { - // spec: "0 0 0 * * *", // Every Day - // task: func() { - // mongoLogger.Info("Began Send daily result notification cron task") - // if err := resultService.CheckAndSendResultNotifications(context.Background(), time.Now().Add(-24*time.Hour)); err != nil { - // mongoLogger.Error("Failed to process result", - // zap.Error(err), - // ) - // } else { - // mongoLogger.Info("Completed sending daily result notification without errors") - // } - // }, - // }, + { + spec: "0 0 0 * * 1", // Every Monday + task: func() { + mongoLogger.Info("Began Send weekly result notification cron task") + if err := resultService.CheckAndSendResultNotifications(context.Background(), time.Now().Add(-7*24*time.Hour)); err != nil { + mongoLogger.Error("Failed to process result", + zap.Error(err), + ) + } else { + mongoLogger.Info("Completed sending weekly result notification without errors") + } + }, + }, } for _, job := range schedule { - // job.task() + job.task() if _, err := c.AddFunc(job.spec, job.task); err != nil { mongoLogger.Error("Failed to schedule data fetching cron job", zap.Error(err), diff --git a/internal/web_server/handlers/event_handler.go b/internal/web_server/handlers/event_handler.go index a149870..5fd0f1f 100644 --- a/internal/web_server/handlers/event_handler.go +++ b/internal/web_server/handlers/event_handler.go @@ -26,7 +26,7 @@ import ( // @Success 200 {array} domain.BaseEvent // @Failure 500 {object} response.APIResponse // @Router /api/v1/events [get] -func (h *Handler) GetAllUpcomingEvents(c *fiber.Ctx) error { +func (h *Handler) GetAllEvents(c *fiber.Ctx) error { page := c.QueryInt("page", 1) pageSize := c.QueryInt("page_size", 10) limit := domain.ValidInt32{ @@ -135,7 +135,7 @@ func (h *Handler) GetAllUpcomingEvents(c *fiber.Ctx) error { } } - events, total, err := h.eventSvc.GetPaginatedUpcomingEvents( + events, total, err := h.eventSvc.GetAllEvents( c.Context(), domain.EventFilter{ SportID: sportID, LeagueID: leagueID, @@ -303,7 +303,18 @@ func (h *Handler) GetTenantUpcomingEvents(c *fiber.Ctx) error { Offset: offset, CountryCode: countryCode, Featured: isFeatured, - Active: domain.ValidBool{Value: true, Valid: true}, + Status: domain.ValidEventStatus{ + Value: domain.STATUS_PENDING, + Valid: true, + }, + IsLive: domain.ValidBool{ + Value: false, + Valid: true, + }, + Active: domain.ValidBool{ + Value: true, + Valid: true, + }, }) // fmt.Printf("League ID: %v", leagueID) @@ -406,18 +417,19 @@ func (h *Handler) GetTopLeagues(c *fiber.Ctx) error { // @Failure 400 {object} response.APIResponse // @Failure 500 {object} response.APIResponse // @Router /api/v1/events/{id} [get] -func (h *Handler) GetUpcomingEventByID(c *fiber.Ctx) error { +func (h *Handler) GetEventByID(c *fiber.Ctx) error { - id := c.Params("id") - if id == "" { - h.BadRequestLogger().Info("Failed to parse event id", zap.String("id", id)) + idStr := c.Params("id") + eventID, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + h.BadRequestLogger().Info("Failed to parse event id", zap.String("id", idStr)) return fiber.NewError(fiber.StatusBadRequest, "Missing id") } - event, err := h.eventSvc.GetUpcomingEventByID(c.Context(), id) + event, err := h.eventSvc.GetEventByID(c.Context(), eventID) if err != nil { - h.InternalServerErrorLogger().Error("Failed to get upcoming event by id", - zap.String("eventID", id), + h.InternalServerErrorLogger().Error("Failed to get event by id", + zap.Int64("eventID", eventID), zap.Error(err), ) return fiber.NewError(fiber.StatusInternalServerError, err.Error()) @@ -446,16 +458,17 @@ func (h *Handler) GetTenantEventByID(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, "invalid company id") } - id := c.Params("id") - if id == "" { - h.BadRequestLogger().Info("Failed to parse event id", zap.String("id", id)) + idStr := c.Params("id") + eventID, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + h.BadRequestLogger().Info("Failed to parse event id", zap.String("id", idStr)) return fiber.NewError(fiber.StatusBadRequest, "Missing id") } - event, err := h.eventSvc.GetEventWithSettingByID(c.Context(), id, companyID.Value) + event, err := h.eventSvc.GetEventWithSettingByID(c.Context(), eventID, companyID.Value) if err != nil { h.InternalServerErrorLogger().Error("Failed to get upcoming event by id", - zap.String("eventID", id), + zap.Int64("eventID", eventID), zap.Error(err), ) return fiber.NewError(fiber.StatusInternalServerError, err.Error()) @@ -482,12 +495,17 @@ type UpdateEventStatusReq struct { // @Failure 500 {object} response.APIResponse // @Router /api/v1/events/{id} [delete] func (h *Handler) SetEventStatusToRemoved(c *fiber.Ctx) error { - eventID := c.Params("id") - err := h.eventSvc.UpdateEventStatus(c.Context(), eventID, domain.STATUS_REMOVED) + idStr := c.Params("id") + eventID, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + h.BadRequestLogger().Info("Failed to parse event id", zap.String("id", idStr)) + return fiber.NewError(fiber.StatusBadRequest, "Missing id") + } + err = h.eventSvc.UpdateEventStatus(c.Context(), eventID, domain.STATUS_REMOVED) if err != nil { h.InternalServerErrorLogger().Error("Failed to update event status", - zap.String("EventID", eventID), + zap.Int64("EventID", eventID), zap.Error(err), ) return fiber.NewError(fiber.StatusInternalServerError, "Failed to update event status") @@ -521,19 +539,26 @@ func (h *Handler) UpdateEventSettings(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, "invalid company id") } - eventID := c.Params("id") + eventIDStr := c.Params("id") + + eventID, err := strconv.ParseInt(eventIDStr, 10, 64) + if err != nil { + h.BadRequestLogger().Error("invalid event id") + return fiber.NewError(fiber.StatusBadRequest, "invalid event id") + } + var req UpdateEventSettingsReq if err := c.BodyParser(&req); err != nil { h.BadRequestLogger().Info("Failed to parse event id", - zap.String("eventID", eventID), + zap.Int64("eventID", eventID), zap.Error(err), ) return fiber.NewError(fiber.StatusBadRequest, err.Error()) } logFields := []zap.Field{ - zap.String("eventID", eventID), + zap.Int64("eventID", eventID), zap.Int64("companyID", companyID.Value), zap.Any("is_featured", req.Featured), zap.Any("is_active", req.IsActive), @@ -550,7 +575,8 @@ func (h *Handler) UpdateEventSettings(c *fiber.Ctx) error { ) return fiber.NewError(fiber.StatusBadRequest, errMsg) } - err := h.eventSvc.UpdateEventSettings(c.Context(), domain.CreateEventSettings{ + + err = h.eventSvc.UpdateEventSettings(c.Context(), domain.CreateEventSettings{ CompanyID: companyID.Value, EventID: eventID, IsFeatured: domain.ConvertBoolPtr(req.Featured), @@ -583,20 +609,25 @@ type SetEventIsMonitoredReq struct { // @Failure 500 {object} response.APIResponse // @Router /api/v1/events/{id}/is_monitored [patch] func (h *Handler) SetEventIsMonitored(c *fiber.Ctx) error { - eventID := c.Params("id") + idStr := c.Params("id") + eventID, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + h.BadRequestLogger().Info("Failed to parse event id", zap.String("id", idStr)) + return fiber.NewError(fiber.StatusBadRequest, "Missing id") + } var req SetEventIsMonitoredReq if err := c.BodyParser(&req); err != nil { h.BadRequestLogger().Info("Failed to parse bet id", - zap.String("eventID", eventID), + zap.Int64("eventID", eventID), zap.Error(err), ) return fiber.NewError(fiber.StatusBadRequest, err.Error()) } logFields := []zap.Field{ - zap.String("eventID", eventID), + zap.Int64("eventID", eventID), zap.Any("is_featured", req.IsMonitored), } valErrs, ok := h.validator.Validate(c, req) @@ -611,7 +642,7 @@ func (h *Handler) SetEventIsMonitored(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, errMsg) } - err := h.eventSvc.UpdateEventMonitored(c.Context(), eventID, req.IsMonitored) + err = h.eventSvc.UpdateEventMonitored(c.Context(), eventID, req.IsMonitored) if err != nil { h.InternalServerErrorLogger().Error("Failed to update event is_monitored", append(logFields, zap.Error(err))...) diff --git a/internal/web_server/handlers/odd_handler.go b/internal/web_server/handlers/odd_handler.go index 192875c..9d7a919 100644 --- a/internal/web_server/handlers/odd_handler.go +++ b/internal/web_server/handlers/odd_handler.go @@ -122,19 +122,21 @@ func (h *Handler) GetOddsByMarketID(c *fiber.Ctx) error { zap.String("upcoming_id", c.Params("upcoming_id")), } - marketID := c.Params("market_id") - if marketID == "" { + marketIDStr := c.Params("market_id") + marketID, err := strconv.ParseInt(marketIDStr, 10, 64) + if err != nil { h.BadRequestLogger().Info("Missing market_id", logFields...) return fiber.NewError(fiber.StatusBadRequest, "Missing market_id") } - upcomingID := c.Params("upcoming_id") - if upcomingID == "" { + eventIDStr := c.Params("upcoming_id") + eventID, err := strconv.ParseInt(eventIDStr, 10, 64) + if err != nil { h.BadRequestLogger().Info("Missing upcoming_id", logFields...) return fiber.NewError(fiber.StatusBadRequest, "Missing upcoming_id") } - rawOdds, err := h.prematchSvc.GetOddsByMarketID(c.Context(), marketID, upcomingID) + rawOdds, err := h.prematchSvc.GetOddsByMarketID(c.Context(), marketID, eventID) if err != nil { // Lets turn this into a warn because this is constantly going off h.InternalServerErrorLogger().Warn("Failed to get raw odds by market ID", append(logFields, zap.Error(err))...) @@ -169,19 +171,21 @@ func (h *Handler) GetTenantOddsByMarketID(c *fiber.Ctx) error { zap.Int64("company_id", companyID.Value), } - marketID := c.Params("market_id") - if marketID == "" { + marketIDStr := c.Params("market_id") + marketID, err := strconv.ParseInt(marketIDStr, 10, 64) + if err != nil { h.BadRequestLogger().Info("Missing market_id", logFields...) return fiber.NewError(fiber.StatusBadRequest, "Missing market_id") } - upcomingID := c.Params("upcoming_id") - if upcomingID == "" { + eventIDStr := c.Params("upcoming_id") + eventID, err := strconv.ParseInt(eventIDStr, 10, 64) + if err != nil { h.BadRequestLogger().Info("Missing upcoming_id", logFields...) return fiber.NewError(fiber.StatusBadRequest, "Missing upcoming_id") } - oddMarket, err := h.prematchSvc.GetOddsWithSettingsByMarketID(c.Context(), marketID, upcomingID, companyID.Value) + oddMarket, err := h.prematchSvc.GetOddsWithSettingsByMarketID(c.Context(), marketID, eventID, companyID.Value) if err != nil { // Lets turn this into a warn because this is constantly going off @@ -213,8 +217,9 @@ func (h *Handler) GetOddsByUpcomingID(c *fiber.Ctx) error { zap.String("offset_param", c.Query("offset", "0")), } - upcomingID := c.Params("upcoming_id") - if upcomingID == "" { + eventIDStr := c.Params("upcoming_id") + eventID, err := strconv.ParseInt(eventIDStr, 10, 64) + if err != nil { h.BadRequestLogger().Info("Missing upcoming_id", logFields...) return fiber.NewError(fiber.StatusBadRequest, "Missing upcoming_id") } @@ -233,7 +238,7 @@ func (h *Handler) GetOddsByUpcomingID(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } - odds, err := h.prematchSvc.GetOddsByEventID(c.Context(), upcomingID, domain.OddMarketWithEventFilter{}) + odds, err := h.prematchSvc.GetOddsByEventID(c.Context(), eventID, domain.OddMarketWithEventFilter{}) if err != nil { logFields = append(logFields, zap.Error(err)) h.InternalServerErrorLogger().Error("Failed to retrieve odds", append(logFields, zap.Error(err))...) @@ -271,8 +276,10 @@ func (h *Handler) GetTenantOddsByUpcomingID(c *fiber.Ctx) error { zap.Int64("company_id", companyID.Value), } - upcomingID := c.Params("upcoming_id") - if upcomingID == "" { + + eventIDStr := c.Params("upcoming_id") + eventID, err := strconv.ParseInt(eventIDStr, 10, 64) + if err != nil { h.BadRequestLogger().Info("Missing upcoming_id", logFields...) return fiber.NewError(fiber.StatusBadRequest, "Missing upcoming_id") } @@ -291,7 +298,7 @@ func (h *Handler) GetTenantOddsByUpcomingID(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } - odds, err := h.prematchSvc.GetOddsWithSettingsByEventID(c.Context(), upcomingID, companyID.Value, domain.OddMarketFilter{}) + odds, err := h.prematchSvc.GetOddsWithSettingsByEventID(c.Context(), eventID, companyID.Value, domain.OddMarketFilter{}) if err != nil { logFields = append(logFields, zap.Error(err)) h.InternalServerErrorLogger().Error("Failed to retrieve odds", append(logFields, zap.Error(err))...) diff --git a/internal/web_server/handlers/result_handler.go b/internal/web_server/handlers/result_handler.go index e045b36..ae153c1 100644 --- a/internal/web_server/handlers/result_handler.go +++ b/internal/web_server/handlers/result_handler.go @@ -26,22 +26,14 @@ type ResultRes struct { // @Success 200 {array} ResultRes // @Failure 400 {object} response.APIResponse // @Failure 500 {object} response.APIResponse -// @Router /api/v1/result/{id} [get] -func (h *Handler) GetResultsByEventID(c *fiber.Ctx) error { - eventID := c.Params("id") - if eventID == "" { - h.mongoLoggerSvc.Info("Event ID is required", - zap.String("eventID", eventID), - zap.Int("status_code", fiber.StatusBadRequest), - zap.Time("timestamp", time.Now()), - ) - return fiber.NewError(fiber.StatusBadRequest, "Event ID is required") - } +// @Router /api/v1/result/b365/{id} [get] +func (h *Handler) GetBet365ResultsByEventID(c *fiber.Ctx) error { + b365EventID := c.Params("id") - results, outcomes, err := h.resultSvc.GetResultsForEvent(c.Context(), eventID) + results, outcomes, err := h.resultSvc.GetBet365ResultForEvent(c.Context(), b365EventID) if err != nil { h.mongoLoggerSvc.Error("Failed to get results by Event ID", - zap.String("eventID", eventID), + zap.String("b365EventID", b365EventID), zap.Int("status_code", fiber.StatusInternalServerError), zap.Error(err), zap.Time("timestamp", time.Now()), diff --git a/internal/web_server/routes.go b/internal/web_server/routes.go index 561d3e7..29c49a9 100644 --- a/internal/web_server/routes.go +++ b/internal/web_server/routes.go @@ -259,8 +259,8 @@ func (a *App) initAppRoutes() { tenant.Get("/odds/upcoming/:upcoming_id/market/:market_id", h.GetTenantOddsByMarketID) tenant.Post("/odds/settings", a.CompanyOnly, h.SaveOddsSetting) - groupV1.Get("/events", a.authMiddleware, h.GetAllUpcomingEvents) - groupV1.Get("/events/:id", a.authMiddleware, h.GetUpcomingEventByID) + groupV1.Get("/events", a.authMiddleware, h.GetAllEvents) + groupV1.Get("/events/:id", a.authMiddleware, h.GetEventByID) groupV1.Delete("/events/:id", a.authMiddleware, a.SuperAdminOnly, h.SetEventStatusToRemoved) groupV1.Patch("/events/:id/is_monitored", a.authMiddleware, a.SuperAdminOnly, h.SetEventIsMonitored) @@ -278,7 +278,7 @@ func (a *App) initAppRoutes() { tenant.Put("/leagues/:id/featured", h.SetLeagueFeatured) groupV1.Get("/leagues", a.authMiddleware, a.SuperAdminOnly, h.GetAllLeagues) - groupV1.Get("/result/:id", h.GetResultsByEventID) + groupV1.Get("/result/b365/:id", h.GetBet365ResultsByEventID) // Branch groupV1.Post("/branch", a.authMiddleware, h.CreateBranch)