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