- Introduced EventWithSettings and EventWithSettingsRes structs for enhanced event data handling. - Implemented conversion functions for creating and updating event settings. - Added support for fetching events with settings from the database. - Created new report data structures for comprehensive reporting capabilities. - Implemented event statistics retrieval and filtering by league and sport. - Added handlers for event statistics endpoints in the web server. - Introduced DateInterval type for managing time intervals in reports.
546 lines
14 KiB
Go
546 lines
14 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: events.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const DeleteEvent = `-- name: DeleteEvent :exec
|
|
DELETE FROM events
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEvent(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteEvent, id)
|
|
return err
|
|
}
|
|
|
|
const GetAllEvents = `-- name: GetAllEvents :many
|
|
SELECT id, source_event_id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, updated_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc, total_outcomes, number_of_bets, total_amount, avg_bet_amount, total_potential_winnings
|
|
FROM event_detailed
|
|
WHERE (
|
|
is_live = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
status = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
league_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
sport_id = $4
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
match_name ILIKE '%' || $5 || '%'
|
|
OR league_name ILIKE '%' || $5 || '%'
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
start_time < $6
|
|
OR $6 IS NULL
|
|
)
|
|
AND (
|
|
start_time > $7
|
|
OR $7 IS NULL
|
|
)
|
|
AND (
|
|
league_cc = $8
|
|
OR $8 IS NULL
|
|
)
|
|
AND (
|
|
source = $9
|
|
OR $9 IS NULL
|
|
)
|
|
ORDER BY start_time ASC
|
|
LIMIT $11 OFFSET $10
|
|
`
|
|
|
|
type GetAllEventsParams struct {
|
|
IsLive pgtype.Bool `json:"is_live"`
|
|
Status pgtype.Text `json:"status"`
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
Query pgtype.Text `json:"query"`
|
|
LastStartTime pgtype.Timestamp `json:"last_start_time"`
|
|
FirstStartTime pgtype.Timestamp `json:"first_start_time"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
Source pgtype.Text `json:"source"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
// TODO: Figure out how to make this code reusable. SQLC prohibits CTEs within multiple queries
|
|
func (q *Queries) GetAllEvents(ctx context.Context, arg GetAllEventsParams) ([]EventDetailed, error) {
|
|
rows, err := q.db.Query(ctx, GetAllEvents,
|
|
arg.IsLive,
|
|
arg.Status,
|
|
arg.LeagueID,
|
|
arg.SportID,
|
|
arg.Query,
|
|
arg.LastStartTime,
|
|
arg.FirstStartTime,
|
|
arg.CountryCode,
|
|
arg.Source,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []EventDetailed
|
|
for rows.Next() {
|
|
var i EventDetailed
|
|
if err := rows.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.UpdatedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.LeagueCc,
|
|
&i.TotalOutcomes,
|
|
&i.NumberOfBets,
|
|
&i.TotalAmount,
|
|
&i.AvgBetAmount,
|
|
&i.TotalPotentialWinnings,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
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, updated_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc, total_outcomes, number_of_bets, total_amount, avg_bet_amount, total_potential_winnings
|
|
FROM event_detailed
|
|
WHERE id = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetEventByID(ctx context.Context, id int64) (EventDetailed, error) {
|
|
row := q.db.QueryRow(ctx, GetEventByID, id)
|
|
var i EventDetailed
|
|
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.UpdatedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.LeagueCc,
|
|
&i.TotalOutcomes,
|
|
&i.NumberOfBets,
|
|
&i.TotalAmount,
|
|
&i.AvgBetAmount,
|
|
&i.TotalPotentialWinnings,
|
|
)
|
|
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, updated_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc, total_outcomes, number_of_bets, total_amount, avg_bet_amount, total_potential_winnings
|
|
FROM event_detailed
|
|
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) (EventDetailed, error) {
|
|
row := q.db.QueryRow(ctx, GetEventBySourceID, arg.SourceEventID, arg.Source)
|
|
var i EventDetailed
|
|
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.UpdatedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.LeagueCc,
|
|
&i.TotalOutcomes,
|
|
&i.NumberOfBets,
|
|
&i.TotalAmount,
|
|
&i.AvgBetAmount,
|
|
&i.TotalPotentialWinnings,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetSportAndLeagueIDs = `-- name: GetSportAndLeagueIDs :one
|
|
SELECT sport_id,
|
|
league_id
|
|
FROM events
|
|
WHERE id = $1
|
|
`
|
|
|
|
type GetSportAndLeagueIDsRow struct {
|
|
SportID int32 `json:"sport_id"`
|
|
LeagueID int64 `json:"league_id"`
|
|
}
|
|
|
|
func (q *Queries) GetSportAndLeagueIDs(ctx context.Context, id int64) (GetSportAndLeagueIDsRow, error) {
|
|
row := q.db.QueryRow(ctx, GetSportAndLeagueIDs, id)
|
|
var i GetSportAndLeagueIDsRow
|
|
err := row.Scan(&i.SportID, &i.LeagueID)
|
|
return i, err
|
|
}
|
|
|
|
const GetTotalEvents = `-- name: GetTotalEvents :one
|
|
SELECT COUNT(*)
|
|
FROM event_detailed
|
|
WHERE (
|
|
is_live = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
status = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
league_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
sport_id = $4
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
match_name ILIKE '%' || $5 || '%'
|
|
OR league_name ILIKE '%' || $5 || '%'
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
start_time < $6
|
|
OR $6 IS NULL
|
|
)
|
|
AND (
|
|
start_time > $7
|
|
OR $7 IS NULL
|
|
)
|
|
AND (
|
|
league_cc = $8
|
|
OR $8 IS NULL
|
|
)
|
|
AND (
|
|
source = $9
|
|
OR $9 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetTotalEventsParams struct {
|
|
IsLive pgtype.Bool `json:"is_live"`
|
|
Status pgtype.Text `json:"status"`
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
Query pgtype.Text `json:"query"`
|
|
LastStartTime pgtype.Timestamp `json:"last_start_time"`
|
|
FirstStartTime pgtype.Timestamp `json:"first_start_time"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
Source pgtype.Text `json:"source"`
|
|
}
|
|
|
|
func (q *Queries) GetTotalEvents(ctx context.Context, arg GetTotalEventsParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetTotalEvents,
|
|
arg.IsLive,
|
|
arg.Status,
|
|
arg.LeagueID,
|
|
arg.SportID,
|
|
arg.Query,
|
|
arg.LastStartTime,
|
|
arg.FirstStartTime,
|
|
arg.CountryCode,
|
|
arg.Source,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const InsertEvent = `-- name: InsertEvent :exec
|
|
INSERT INTO events (
|
|
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,
|
|
is_live,
|
|
status,
|
|
source,
|
|
default_winning_upper_limit
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12,
|
|
$13,
|
|
$14,
|
|
$15,
|
|
$16
|
|
) ON CONFLICT (source_event_id, source) DO
|
|
UPDATE
|
|
SET sport_id = EXCLUDED.sport_id,
|
|
match_name = EXCLUDED.match_name,
|
|
home_team = EXCLUDED.home_team,
|
|
away_team = EXCLUDED.away_team,
|
|
home_team_id = EXCLUDED.home_team_id,
|
|
away_team_id = EXCLUDED.away_team_id,
|
|
home_kit_image = EXCLUDED.home_kit_image,
|
|
away_kit_image = EXCLUDED.away_kit_image,
|
|
league_id = EXCLUDED.league_id,
|
|
league_name = EXCLUDED.league_name,
|
|
start_time = EXCLUDED.start_time,
|
|
score = EXCLUDED.score,
|
|
match_minute = EXCLUDED.match_minute,
|
|
timer_status = EXCLUDED.timer_status,
|
|
added_time = EXCLUDED.added_time,
|
|
match_period = EXCLUDED.match_period,
|
|
is_live = EXCLUDED.is_live,
|
|
source = EXCLUDED.source,
|
|
default_winning_upper_limit = EXCLUDED.default_winning_upper_limit,
|
|
fetched_at = now()
|
|
`
|
|
|
|
type InsertEventParams struct {
|
|
SourceEventID string `json:"source_event_id"`
|
|
SportID int32 `json:"sport_id"`
|
|
MatchName string `json:"match_name"`
|
|
HomeTeam string `json:"home_team"`
|
|
AwayTeam string `json:"away_team"`
|
|
HomeTeamID int64 `json:"home_team_id"`
|
|
AwayTeamID int64 `json:"away_team_id"`
|
|
HomeKitImage string `json:"home_kit_image"`
|
|
AwayKitImage string `json:"away_kit_image"`
|
|
LeagueID int64 `json:"league_id"`
|
|
LeagueName string `json:"league_name"`
|
|
StartTime pgtype.Timestamp `json:"start_time"`
|
|
IsLive bool `json:"is_live"`
|
|
Status string `json:"status"`
|
|
Source string `json:"source"`
|
|
DefaultWinningUpperLimit int64 `json:"default_winning_upper_limit"`
|
|
}
|
|
|
|
func (q *Queries) InsertEvent(ctx context.Context, arg InsertEventParams) error {
|
|
_, err := q.db.Exec(ctx, InsertEvent,
|
|
arg.SourceEventID,
|
|
arg.SportID,
|
|
arg.MatchName,
|
|
arg.HomeTeam,
|
|
arg.AwayTeam,
|
|
arg.HomeTeamID,
|
|
arg.AwayTeamID,
|
|
arg.HomeKitImage,
|
|
arg.AwayKitImage,
|
|
arg.LeagueID,
|
|
arg.LeagueName,
|
|
arg.StartTime,
|
|
arg.IsLive,
|
|
arg.Status,
|
|
arg.Source,
|
|
arg.DefaultWinningUpperLimit,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const IsEventMonitored = `-- name: IsEventMonitored :one
|
|
SELECT is_monitored
|
|
FROM events
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) IsEventMonitored(ctx context.Context, id int64) (bool, error) {
|
|
row := q.db.QueryRow(ctx, IsEventMonitored, id)
|
|
var is_monitored bool
|
|
err := row.Scan(&is_monitored)
|
|
return is_monitored, err
|
|
}
|
|
|
|
const ListLiveEvents = `-- name: ListLiveEvents :many
|
|
SELECT id
|
|
FROM event_detailed
|
|
WHERE is_live = true
|
|
`
|
|
|
|
func (q *Queries) ListLiveEvents(ctx context.Context) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListLiveEvents)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var id int64
|
|
if err := rows.Scan(&id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateEventMonitored = `-- name: UpdateEventMonitored :exec
|
|
UPDATE events
|
|
SET is_monitored = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $2
|
|
`
|
|
|
|
type UpdateEventMonitoredParams struct {
|
|
IsMonitored bool `json:"is_monitored"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateEventMonitored(ctx context.Context, arg UpdateEventMonitoredParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateEventMonitored, arg.IsMonitored, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const UpdateGlobalEventSettings = `-- name: UpdateGlobalEventSettings :exec
|
|
UPDATE events
|
|
SET default_is_active = COALESCE($2, default_is_active),
|
|
default_is_featured = COALESCE(
|
|
$3,
|
|
default_is_featured
|
|
),
|
|
default_winning_upper_limit = COALESCE(
|
|
$4,
|
|
default_winning_upper_limit
|
|
),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateGlobalEventSettingsParams struct {
|
|
ID int64 `json:"id"`
|
|
DefaultIsActive pgtype.Bool `json:"default_is_active"`
|
|
DefaultIsFeatured pgtype.Bool `json:"default_is_featured"`
|
|
DefaultWinningUpperLimit pgtype.Int8 `json:"default_winning_upper_limit"`
|
|
}
|
|
|
|
func (q *Queries) UpdateGlobalEventSettings(ctx context.Context, arg UpdateGlobalEventSettingsParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateGlobalEventSettings,
|
|
arg.ID,
|
|
arg.DefaultIsActive,
|
|
arg.DefaultIsFeatured,
|
|
arg.DefaultWinningUpperLimit,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const UpdateMatchResult = `-- name: UpdateMatchResult :exec
|
|
UPDATE events
|
|
SET score = $1,
|
|
status = $2
|
|
WHERE id = $3
|
|
`
|
|
|
|
type UpdateMatchResultParams struct {
|
|
Score pgtype.Text `json:"score"`
|
|
Status string `json:"status"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateMatchResult(ctx context.Context, arg UpdateMatchResultParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateMatchResult, arg.Score, arg.Status, arg.ID)
|
|
return err
|
|
}
|