refactor events table
This commit is contained in:
parent
84bbe53bb7
commit
eb4f267142
|
|
@ -183,15 +183,15 @@ CREATE TABLE IF NOT EXISTS branch_cashiers (
|
||||||
);
|
);
|
||||||
CREATE TABLE events (
|
CREATE TABLE events (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
sport_id TEXT,
|
sport_id INT,
|
||||||
match_name TEXT,
|
match_name TEXT,
|
||||||
home_team TEXT,
|
home_team TEXT,
|
||||||
away_team TEXT,
|
away_team TEXT,
|
||||||
home_team_id TEXT,
|
home_team_id INT,
|
||||||
away_team_id TEXT,
|
away_team_id INT,
|
||||||
home_kit_image TEXT,
|
home_kit_image TEXT,
|
||||||
away_kit_image TEXT,
|
away_kit_image TEXT,
|
||||||
league_id TEXT,
|
league_id INT,
|
||||||
league_name TEXT,
|
league_name TEXT,
|
||||||
league_cc TEXT,
|
league_cc TEXT,
|
||||||
start_time TIMESTAMP,
|
start_time TIMESTAMP,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by sqlc. DO NOT EDIT.
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// sqlc v1.28.0
|
// sqlc v1.29.0
|
||||||
// source: cashier.sql
|
// source: cashier.sql
|
||||||
|
|
||||||
package dbgen
|
package dbgen
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,15 @@ ORDER BY start_time ASC
|
||||||
|
|
||||||
type GetAllUpcomingEventsRow struct {
|
type GetAllUpcomingEventsRow struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
MatchName pgtype.Text `json:"match_name"`
|
MatchName pgtype.Text `json:"match_name"`
|
||||||
HomeTeam pgtype.Text `json:"home_team"`
|
HomeTeam pgtype.Text `json:"home_team"`
|
||||||
AwayTeam pgtype.Text `json:"away_team"`
|
AwayTeam pgtype.Text `json:"away_team"`
|
||||||
HomeTeamID pgtype.Text `json:"home_team_id"`
|
HomeTeamID pgtype.Int4 `json:"home_team_id"`
|
||||||
AwayTeamID pgtype.Text `json:"away_team_id"`
|
AwayTeamID pgtype.Int4 `json:"away_team_id"`
|
||||||
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
||||||
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
LeagueName pgtype.Text `json:"league_name"`
|
LeagueName pgtype.Text `json:"league_name"`
|
||||||
LeagueCc pgtype.Text `json:"league_cc"`
|
LeagueCc pgtype.Text `json:"league_cc"`
|
||||||
StartTime pgtype.Timestamp `json:"start_time"`
|
StartTime pgtype.Timestamp `json:"start_time"`
|
||||||
|
|
@ -128,15 +128,15 @@ ORDER BY start_time ASC
|
||||||
|
|
||||||
type GetExpiredUpcomingEventsRow struct {
|
type GetExpiredUpcomingEventsRow struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
MatchName pgtype.Text `json:"match_name"`
|
MatchName pgtype.Text `json:"match_name"`
|
||||||
HomeTeam pgtype.Text `json:"home_team"`
|
HomeTeam pgtype.Text `json:"home_team"`
|
||||||
AwayTeam pgtype.Text `json:"away_team"`
|
AwayTeam pgtype.Text `json:"away_team"`
|
||||||
HomeTeamID pgtype.Text `json:"home_team_id"`
|
HomeTeamID pgtype.Int4 `json:"home_team_id"`
|
||||||
AwayTeamID pgtype.Text `json:"away_team_id"`
|
AwayTeamID pgtype.Int4 `json:"away_team_id"`
|
||||||
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
||||||
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
LeagueName pgtype.Text `json:"league_name"`
|
LeagueName pgtype.Text `json:"league_name"`
|
||||||
LeagueCc pgtype.Text `json:"league_cc"`
|
LeagueCc pgtype.Text `json:"league_cc"`
|
||||||
StartTime pgtype.Timestamp `json:"start_time"`
|
StartTime pgtype.Timestamp `json:"start_time"`
|
||||||
|
|
@ -226,8 +226,8 @@ LIMIT $6 OFFSET $5
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetPaginatedUpcomingEventsParams struct {
|
type GetPaginatedUpcomingEventsParams struct {
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
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"`
|
||||||
Offset pgtype.Int4 `json:"offset"`
|
Offset pgtype.Int4 `json:"offset"`
|
||||||
|
|
@ -236,15 +236,15 @@ type GetPaginatedUpcomingEventsParams struct {
|
||||||
|
|
||||||
type GetPaginatedUpcomingEventsRow struct {
|
type GetPaginatedUpcomingEventsRow struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
MatchName pgtype.Text `json:"match_name"`
|
MatchName pgtype.Text `json:"match_name"`
|
||||||
HomeTeam pgtype.Text `json:"home_team"`
|
HomeTeam pgtype.Text `json:"home_team"`
|
||||||
AwayTeam pgtype.Text `json:"away_team"`
|
AwayTeam pgtype.Text `json:"away_team"`
|
||||||
HomeTeamID pgtype.Text `json:"home_team_id"`
|
HomeTeamID pgtype.Int4 `json:"home_team_id"`
|
||||||
AwayTeamID pgtype.Text `json:"away_team_id"`
|
AwayTeamID pgtype.Int4 `json:"away_team_id"`
|
||||||
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
||||||
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
LeagueName pgtype.Text `json:"league_name"`
|
LeagueName pgtype.Text `json:"league_name"`
|
||||||
LeagueCc pgtype.Text `json:"league_cc"`
|
LeagueCc pgtype.Text `json:"league_cc"`
|
||||||
StartTime pgtype.Timestamp `json:"start_time"`
|
StartTime pgtype.Timestamp `json:"start_time"`
|
||||||
|
|
@ -323,8 +323,8 @@ WHERE is_live = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetTotalEventsParams struct {
|
type GetTotalEventsParams struct {
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
@ -368,15 +368,15 @@ LIMIT 1
|
||||||
|
|
||||||
type GetUpcomingByIDRow struct {
|
type GetUpcomingByIDRow struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
MatchName pgtype.Text `json:"match_name"`
|
MatchName pgtype.Text `json:"match_name"`
|
||||||
HomeTeam pgtype.Text `json:"home_team"`
|
HomeTeam pgtype.Text `json:"home_team"`
|
||||||
AwayTeam pgtype.Text `json:"away_team"`
|
AwayTeam pgtype.Text `json:"away_team"`
|
||||||
HomeTeamID pgtype.Text `json:"home_team_id"`
|
HomeTeamID pgtype.Int4 `json:"home_team_id"`
|
||||||
AwayTeamID pgtype.Text `json:"away_team_id"`
|
AwayTeamID pgtype.Int4 `json:"away_team_id"`
|
||||||
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
||||||
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
LeagueName pgtype.Text `json:"league_name"`
|
LeagueName pgtype.Text `json:"league_name"`
|
||||||
LeagueCc pgtype.Text `json:"league_cc"`
|
LeagueCc pgtype.Text `json:"league_cc"`
|
||||||
StartTime pgtype.Timestamp `json:"start_time"`
|
StartTime pgtype.Timestamp `json:"start_time"`
|
||||||
|
|
@ -484,15 +484,15 @@ SET sport_id = EXCLUDED.sport_id,
|
||||||
|
|
||||||
type InsertEventParams struct {
|
type InsertEventParams struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
MatchName pgtype.Text `json:"match_name"`
|
MatchName pgtype.Text `json:"match_name"`
|
||||||
HomeTeam pgtype.Text `json:"home_team"`
|
HomeTeam pgtype.Text `json:"home_team"`
|
||||||
AwayTeam pgtype.Text `json:"away_team"`
|
AwayTeam pgtype.Text `json:"away_team"`
|
||||||
HomeTeamID pgtype.Text `json:"home_team_id"`
|
HomeTeamID pgtype.Int4 `json:"home_team_id"`
|
||||||
AwayTeamID pgtype.Text `json:"away_team_id"`
|
AwayTeamID pgtype.Int4 `json:"away_team_id"`
|
||||||
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
||||||
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
LeagueName pgtype.Text `json:"league_name"`
|
LeagueName pgtype.Text `json:"league_name"`
|
||||||
LeagueCc pgtype.Text `json:"league_cc"`
|
LeagueCc pgtype.Text `json:"league_cc"`
|
||||||
StartTime pgtype.Timestamp `json:"start_time"`
|
StartTime pgtype.Timestamp `json:"start_time"`
|
||||||
|
|
@ -591,15 +591,15 @@ SET sport_id = EXCLUDED.sport_id,
|
||||||
|
|
||||||
type InsertUpcomingEventParams struct {
|
type InsertUpcomingEventParams struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
MatchName pgtype.Text `json:"match_name"`
|
MatchName pgtype.Text `json:"match_name"`
|
||||||
HomeTeam pgtype.Text `json:"home_team"`
|
HomeTeam pgtype.Text `json:"home_team"`
|
||||||
AwayTeam pgtype.Text `json:"away_team"`
|
AwayTeam pgtype.Text `json:"away_team"`
|
||||||
HomeTeamID pgtype.Text `json:"home_team_id"`
|
HomeTeamID pgtype.Int4 `json:"home_team_id"`
|
||||||
AwayTeamID pgtype.Text `json:"away_team_id"`
|
AwayTeamID pgtype.Int4 `json:"away_team_id"`
|
||||||
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
||||||
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
LeagueName pgtype.Text `json:"league_name"`
|
LeagueName pgtype.Text `json:"league_name"`
|
||||||
LeagueCc pgtype.Text `json:"league_cc"`
|
LeagueCc pgtype.Text `json:"league_cc"`
|
||||||
StartTime pgtype.Timestamp `json:"start_time"`
|
StartTime pgtype.Timestamp `json:"start_time"`
|
||||||
|
|
|
||||||
|
|
@ -176,15 +176,15 @@ type CustomerWallet struct {
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SportID pgtype.Text `json:"sport_id"`
|
SportID pgtype.Int4 `json:"sport_id"`
|
||||||
MatchName pgtype.Text `json:"match_name"`
|
MatchName pgtype.Text `json:"match_name"`
|
||||||
HomeTeam pgtype.Text `json:"home_team"`
|
HomeTeam pgtype.Text `json:"home_team"`
|
||||||
AwayTeam pgtype.Text `json:"away_team"`
|
AwayTeam pgtype.Text `json:"away_team"`
|
||||||
HomeTeamID pgtype.Text `json:"home_team_id"`
|
HomeTeamID pgtype.Int4 `json:"home_team_id"`
|
||||||
AwayTeamID pgtype.Text `json:"away_team_id"`
|
AwayTeamID pgtype.Int4 `json:"away_team_id"`
|
||||||
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
HomeKitImage pgtype.Text `json:"home_kit_image"`
|
||||||
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
AwayKitImage pgtype.Text `json:"away_kit_image"`
|
||||||
LeagueID pgtype.Text `json:"league_id"`
|
LeagueID pgtype.Int4 `json:"league_id"`
|
||||||
LeagueName pgtype.Text `json:"league_name"`
|
LeagueName pgtype.Text `json:"league_name"`
|
||||||
LeagueCc pgtype.Text `json:"league_cc"`
|
LeagueCc pgtype.Text `json:"league_cc"`
|
||||||
StartTime pgtype.Timestamp `json:"start_time"`
|
StartTime pgtype.Timestamp `json:"start_time"`
|
||||||
|
|
@ -383,6 +383,32 @@ type User struct {
|
||||||
ReferredBy pgtype.Text `json:"referred_by"`
|
ReferredBy pgtype.Text `json:"referred_by"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserGameInteraction struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
GameID int64 `json:"game_id"`
|
||||||
|
InteractionType string `json:"interaction_type"`
|
||||||
|
Amount pgtype.Numeric `json:"amount"`
|
||||||
|
DurationSeconds pgtype.Int4 `json:"duration_seconds"`
|
||||||
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type VirtualGame struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Category string `json:"category"`
|
||||||
|
MinBet pgtype.Numeric `json:"min_bet"`
|
||||||
|
MaxBet pgtype.Numeric `json:"max_bet"`
|
||||||
|
Volatility string `json:"volatility"`
|
||||||
|
Rtp pgtype.Numeric `json:"rtp"`
|
||||||
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
||||||
|
PopularityScore pgtype.Int4 `json:"popularity_score"`
|
||||||
|
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
|
||||||
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
type VirtualGameSession struct {
|
type VirtualGameSession struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UserID int64 `json:"user_id"`
|
UserID int64 `json:"user_id"`
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ type ValidInt struct {
|
||||||
Value int
|
Value int
|
||||||
Valid bool
|
Valid bool
|
||||||
}
|
}
|
||||||
|
type ValidInt32 struct {
|
||||||
|
Value int32
|
||||||
|
Valid bool
|
||||||
|
}
|
||||||
|
|
||||||
type ValidString struct {
|
type ValidString struct {
|
||||||
Value string
|
Value string
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@ import "time"
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
ID string
|
ID string
|
||||||
SportID string
|
SportID int32
|
||||||
MatchName string
|
MatchName string
|
||||||
HomeTeam string
|
HomeTeam string
|
||||||
AwayTeam string
|
AwayTeam string
|
||||||
HomeTeamID string
|
HomeTeamID int32
|
||||||
AwayTeamID string
|
AwayTeamID int32
|
||||||
HomeKitImage string
|
HomeKitImage string
|
||||||
AwayKitImage string
|
AwayKitImage string
|
||||||
LeagueID string
|
LeagueID int32
|
||||||
LeagueName string
|
LeagueName string
|
||||||
LeagueCC string
|
LeagueCC string
|
||||||
StartTime string
|
StartTime string
|
||||||
|
|
@ -54,15 +54,15 @@ type BetResult struct {
|
||||||
|
|
||||||
type UpcomingEvent struct {
|
type UpcomingEvent struct {
|
||||||
ID string // Event ID
|
ID string // Event ID
|
||||||
SportID string // Sport ID
|
SportID int32 // Sport ID
|
||||||
MatchName string // Match or event name
|
MatchName string // Match or event name
|
||||||
HomeTeam string // Home team name (if available)
|
HomeTeam string // Home team name (if available)
|
||||||
AwayTeam string // Away team name (can be empty/null)
|
AwayTeam string // Away team name (can be empty/null)
|
||||||
HomeTeamID string // Home team ID
|
HomeTeamID int32 // Home team ID
|
||||||
AwayTeamID string // Away team ID (can be empty/null)
|
AwayTeamID int32 // Away team ID (can be empty/null)
|
||||||
HomeKitImage string // Kit or image for home team (optional)
|
HomeKitImage string // Kit or image for home team (optional)
|
||||||
AwayKitImage string // Kit or image for away team (optional)
|
AwayKitImage string // Kit or image for away team (optional)
|
||||||
LeagueID string // League ID
|
LeagueID int32 // League ID
|
||||||
LeagueName string // League name
|
LeagueName string // League name
|
||||||
LeagueCC string // League country code
|
LeagueCC string // League country code
|
||||||
StartTime time.Time // Converted from "time" field in UNIX format
|
StartTime time.Time // Converted from "time" field in UNIX format
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,15 @@ func (s *Store) SaveEvent(ctx context.Context, e domain.Event) error {
|
||||||
|
|
||||||
return s.queries.InsertEvent(ctx, dbgen.InsertEventParams{
|
return s.queries.InsertEvent(ctx, dbgen.InsertEventParams{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
SportID: pgtype.Text{String: e.SportID, Valid: true},
|
SportID: pgtype.Int4{Int32: e.SportID, Valid: true},
|
||||||
MatchName: pgtype.Text{String: e.MatchName, Valid: true},
|
MatchName: pgtype.Text{String: e.MatchName, Valid: true},
|
||||||
HomeTeam: pgtype.Text{String: e.HomeTeam, Valid: true},
|
HomeTeam: pgtype.Text{String: e.HomeTeam, Valid: true},
|
||||||
AwayTeam: pgtype.Text{String: e.AwayTeam, Valid: true},
|
AwayTeam: pgtype.Text{String: e.AwayTeam, Valid: true},
|
||||||
HomeTeamID: pgtype.Text{String: e.HomeTeamID, Valid: true},
|
HomeTeamID: pgtype.Int4{Int32: e.HomeTeamID, Valid: true},
|
||||||
AwayTeamID: pgtype.Text{String: e.AwayTeamID, Valid: true},
|
AwayTeamID: pgtype.Int4{Int32: e.AwayTeamID, Valid: true},
|
||||||
HomeKitImage: pgtype.Text{String: e.HomeKitImage, Valid: true},
|
HomeKitImage: pgtype.Text{String: e.HomeKitImage, Valid: true},
|
||||||
AwayKitImage: pgtype.Text{String: e.AwayKitImage, Valid: true},
|
AwayKitImage: pgtype.Text{String: e.AwayKitImage, Valid: true},
|
||||||
LeagueID: pgtype.Text{String: e.LeagueID, Valid: true},
|
LeagueID: pgtype.Int4{Int32: e.LeagueID, Valid: true},
|
||||||
LeagueName: pgtype.Text{String: e.LeagueName, Valid: true},
|
LeagueName: pgtype.Text{String: e.LeagueName, Valid: true},
|
||||||
LeagueCc: pgtype.Text{String: e.LeagueCC, Valid: true},
|
LeagueCc: pgtype.Text{String: e.LeagueCC, Valid: true},
|
||||||
StartTime: pgtype.Timestamp{Time: parsedTime, Valid: true},
|
StartTime: pgtype.Timestamp{Time: parsedTime, Valid: true},
|
||||||
|
|
@ -46,15 +46,15 @@ func (s *Store) SaveEvent(ctx context.Context, e domain.Event) error {
|
||||||
func (s *Store) SaveUpcomingEvent(ctx context.Context, e domain.UpcomingEvent) error {
|
func (s *Store) SaveUpcomingEvent(ctx context.Context, e domain.UpcomingEvent) error {
|
||||||
return s.queries.InsertUpcomingEvent(ctx, dbgen.InsertUpcomingEventParams{
|
return s.queries.InsertUpcomingEvent(ctx, dbgen.InsertUpcomingEventParams{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
SportID: pgtype.Text{String: e.SportID, Valid: true},
|
SportID: pgtype.Int4{Int32: e.SportID, Valid: true},
|
||||||
MatchName: pgtype.Text{String: e.MatchName, Valid: true},
|
MatchName: pgtype.Text{String: e.MatchName, Valid: true},
|
||||||
HomeTeam: pgtype.Text{String: e.HomeTeam, Valid: true},
|
HomeTeam: pgtype.Text{String: e.HomeTeam, Valid: true},
|
||||||
AwayTeam: pgtype.Text{String: e.AwayTeam, Valid: true},
|
AwayTeam: pgtype.Text{String: e.AwayTeam, Valid: true},
|
||||||
HomeTeamID: pgtype.Text{String: e.HomeTeamID, Valid: true},
|
HomeTeamID: pgtype.Int4{Int32: e.HomeTeamID, Valid: true},
|
||||||
AwayTeamID: pgtype.Text{String: e.AwayTeamID, Valid: true},
|
AwayTeamID: pgtype.Int4{Int32: e.AwayTeamID, Valid: true},
|
||||||
HomeKitImage: pgtype.Text{String: e.HomeKitImage, Valid: true},
|
HomeKitImage: pgtype.Text{String: e.HomeKitImage, Valid: true},
|
||||||
AwayKitImage: pgtype.Text{String: e.AwayKitImage, Valid: true},
|
AwayKitImage: pgtype.Text{String: e.AwayKitImage, Valid: true},
|
||||||
LeagueID: pgtype.Text{String: e.LeagueID, Valid: true},
|
LeagueID: pgtype.Int4{Int32: e.LeagueID, Valid: true},
|
||||||
LeagueName: pgtype.Text{String: e.LeagueName, Valid: true},
|
LeagueName: pgtype.Text{String: e.LeagueName, Valid: true},
|
||||||
LeagueCc: pgtype.Text{String: e.LeagueCC, Valid: true},
|
LeagueCc: pgtype.Text{String: e.LeagueCC, Valid: true},
|
||||||
StartTime: pgtype.Timestamp{Time: e.StartTime, Valid: true},
|
StartTime: pgtype.Timestamp{Time: e.StartTime, Valid: true},
|
||||||
|
|
@ -75,15 +75,15 @@ func (s *Store) GetAllUpcomingEvents(ctx context.Context) ([]domain.UpcomingEven
|
||||||
for i, e := range events {
|
for i, e := range events {
|
||||||
upcomingEvents[i] = domain.UpcomingEvent{
|
upcomingEvents[i] = domain.UpcomingEvent{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
SportID: e.SportID.String,
|
SportID: e.SportID.Int32,
|
||||||
MatchName: e.MatchName.String,
|
MatchName: e.MatchName.String,
|
||||||
HomeTeam: e.HomeTeam.String,
|
HomeTeam: e.HomeTeam.String,
|
||||||
AwayTeam: e.AwayTeam.String,
|
AwayTeam: e.AwayTeam.String,
|
||||||
HomeTeamID: e.HomeTeamID.String,
|
HomeTeamID: e.HomeTeamID.Int32,
|
||||||
AwayTeamID: e.AwayTeamID.String,
|
AwayTeamID: e.AwayTeamID.Int32,
|
||||||
HomeKitImage: e.HomeKitImage.String,
|
HomeKitImage: e.HomeKitImage.String,
|
||||||
AwayKitImage: e.AwayKitImage.String,
|
AwayKitImage: e.AwayKitImage.String,
|
||||||
LeagueID: e.LeagueID.String,
|
LeagueID: e.LeagueID.Int32,
|
||||||
LeagueName: e.LeagueName.String,
|
LeagueName: e.LeagueName.String,
|
||||||
LeagueCC: e.LeagueCc.String,
|
LeagueCC: e.LeagueCc.String,
|
||||||
StartTime: e.StartTime.Time.UTC(),
|
StartTime: e.StartTime.Time.UTC(),
|
||||||
|
|
@ -103,15 +103,15 @@ func (s *Store) GetExpiredUpcomingEvents(ctx context.Context) ([]domain.Upcoming
|
||||||
for i, e := range events {
|
for i, e := range events {
|
||||||
upcomingEvents[i] = domain.UpcomingEvent{
|
upcomingEvents[i] = domain.UpcomingEvent{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
SportID: e.SportID.String,
|
SportID: e.SportID.Int32,
|
||||||
MatchName: e.MatchName.String,
|
MatchName: e.MatchName.String,
|
||||||
HomeTeam: e.HomeTeam.String,
|
HomeTeam: e.HomeTeam.String,
|
||||||
AwayTeam: e.AwayTeam.String,
|
AwayTeam: e.AwayTeam.String,
|
||||||
HomeTeamID: e.HomeTeamID.String,
|
HomeTeamID: e.HomeTeamID.Int32,
|
||||||
AwayTeamID: e.AwayTeamID.String,
|
AwayTeamID: e.AwayTeamID.Int32,
|
||||||
HomeKitImage: e.HomeKitImage.String,
|
HomeKitImage: e.HomeKitImage.String,
|
||||||
AwayKitImage: e.AwayKitImage.String,
|
AwayKitImage: e.AwayKitImage.String,
|
||||||
LeagueID: e.LeagueID.String,
|
LeagueID: e.LeagueID.Int32,
|
||||||
LeagueName: e.LeagueName.String,
|
LeagueName: e.LeagueName.String,
|
||||||
LeagueCC: e.LeagueCc.String,
|
LeagueCC: e.LeagueCc.String,
|
||||||
StartTime: e.StartTime.Time.UTC(),
|
StartTime: e.StartTime.Time.UTC(),
|
||||||
|
|
@ -121,16 +121,16 @@ func (s *Store) GetExpiredUpcomingEvents(ctx context.Context) ([]domain.Upcoming
|
||||||
return upcomingEvents, nil
|
return upcomingEvents, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, limit domain.ValidInt64, offset domain.ValidInt64, leagueID domain.ValidString, sportID domain.ValidString, firstStartTime domain.ValidTime, lastStartTime domain.ValidTime) ([]domain.UpcomingEvent, int64, error) {
|
func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, limit domain.ValidInt64, offset domain.ValidInt64, leagueID domain.ValidInt32, sportID domain.ValidInt32, firstStartTime domain.ValidTime, lastStartTime domain.ValidTime) ([]domain.UpcomingEvent, int64, error) {
|
||||||
|
|
||||||
events, err := s.queries.GetPaginatedUpcomingEvents(ctx, dbgen.GetPaginatedUpcomingEventsParams{
|
events, err := s.queries.GetPaginatedUpcomingEvents(ctx, dbgen.GetPaginatedUpcomingEventsParams{
|
||||||
LeagueID: pgtype.Text{
|
LeagueID: pgtype.Int4{
|
||||||
String: leagueID.Value,
|
Int32: leagueID.Value,
|
||||||
Valid: leagueID.Valid,
|
Valid: leagueID.Valid,
|
||||||
},
|
},
|
||||||
SportID: pgtype.Text{
|
SportID: pgtype.Int4{
|
||||||
String: sportID.Value,
|
Int32: sportID.Value,
|
||||||
Valid: sportID.Valid,
|
Valid: sportID.Valid,
|
||||||
},
|
},
|
||||||
Limit: pgtype.Int4{
|
Limit: pgtype.Int4{
|
||||||
Int32: int32(limit.Value),
|
Int32: int32(limit.Value),
|
||||||
|
|
@ -157,15 +157,15 @@ func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, limit domain.Val
|
||||||
for i, e := range events {
|
for i, e := range events {
|
||||||
upcomingEvents[i] = domain.UpcomingEvent{
|
upcomingEvents[i] = domain.UpcomingEvent{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
SportID: e.SportID.String,
|
SportID: e.SportID.Int32,
|
||||||
MatchName: e.MatchName.String,
|
MatchName: e.MatchName.String,
|
||||||
HomeTeam: e.HomeTeam.String,
|
HomeTeam: e.HomeTeam.String,
|
||||||
AwayTeam: e.AwayTeam.String,
|
AwayTeam: e.AwayTeam.String,
|
||||||
HomeTeamID: e.HomeTeamID.String,
|
HomeTeamID: e.HomeTeamID.Int32,
|
||||||
AwayTeamID: e.AwayTeamID.String,
|
AwayTeamID: e.AwayTeamID.Int32,
|
||||||
HomeKitImage: e.HomeKitImage.String,
|
HomeKitImage: e.HomeKitImage.String,
|
||||||
AwayKitImage: e.AwayKitImage.String,
|
AwayKitImage: e.AwayKitImage.String,
|
||||||
LeagueID: e.LeagueID.String,
|
LeagueID: e.LeagueID.Int32,
|
||||||
LeagueName: e.LeagueName.String,
|
LeagueName: e.LeagueName.String,
|
||||||
LeagueCC: e.LeagueCc.String,
|
LeagueCC: e.LeagueCc.String,
|
||||||
StartTime: e.StartTime.Time.UTC(),
|
StartTime: e.StartTime.Time.UTC(),
|
||||||
|
|
@ -173,13 +173,13 @@ func (s *Store) GetPaginatedUpcomingEvents(ctx context.Context, limit domain.Val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalCount, err := s.queries.GetTotalEvents(ctx, dbgen.GetTotalEventsParams{
|
totalCount, err := s.queries.GetTotalEvents(ctx, dbgen.GetTotalEventsParams{
|
||||||
LeagueID: pgtype.Text{
|
LeagueID: pgtype.Int4{
|
||||||
String: leagueID.Value,
|
Int32: leagueID.Value,
|
||||||
Valid: leagueID.Valid,
|
Valid: leagueID.Valid,
|
||||||
},
|
},
|
||||||
SportID: pgtype.Text{
|
SportID: pgtype.Int4{
|
||||||
String: sportID.Value,
|
Int32: sportID.Value,
|
||||||
Valid: sportID.Valid,
|
Valid: sportID.Valid,
|
||||||
},
|
},
|
||||||
FirstStartTime: pgtype.Timestamp{
|
FirstStartTime: pgtype.Timestamp{
|
||||||
Time: firstStartTime.Value.UTC(),
|
Time: firstStartTime.Value.UTC(),
|
||||||
|
|
@ -205,15 +205,15 @@ func (s *Store) GetUpcomingEventByID(ctx context.Context, ID string) (domain.Upc
|
||||||
|
|
||||||
return domain.UpcomingEvent{
|
return domain.UpcomingEvent{
|
||||||
ID: event.ID,
|
ID: event.ID,
|
||||||
SportID: event.SportID.String,
|
SportID: event.SportID.Int32,
|
||||||
MatchName: event.MatchName.String,
|
MatchName: event.MatchName.String,
|
||||||
HomeTeam: event.HomeTeam.String,
|
HomeTeam: event.HomeTeam.String,
|
||||||
AwayTeam: event.AwayTeam.String,
|
AwayTeam: event.AwayTeam.String,
|
||||||
HomeTeamID: event.HomeTeamID.String,
|
HomeTeamID: event.HomeTeamID.Int32,
|
||||||
AwayTeamID: event.AwayTeamID.String,
|
AwayTeamID: event.AwayTeamID.Int32,
|
||||||
HomeKitImage: event.HomeKitImage.String,
|
HomeKitImage: event.HomeKitImage.String,
|
||||||
AwayKitImage: event.AwayKitImage.String,
|
AwayKitImage: event.AwayKitImage.String,
|
||||||
LeagueID: event.LeagueID.String,
|
LeagueID: event.LeagueID.Int32,
|
||||||
LeagueName: event.LeagueName.String,
|
LeagueName: event.LeagueName.String,
|
||||||
LeagueCC: event.LeagueCc.String,
|
LeagueCC: event.LeagueCc.String,
|
||||||
StartTime: event.StartTime.Time.UTC(),
|
StartTime: event.StartTime.Time.UTC(),
|
||||||
|
|
|
||||||
|
|
@ -121,15 +121,11 @@ func (s *Service) GenerateBetOutcome(ctx context.Context, eventID int64, marketI
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.CreateBetOutcome{}, err
|
return domain.CreateBetOutcome{}, err
|
||||||
}
|
}
|
||||||
sportID, err := strconv.ParseInt(event.SportID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return domain.CreateBetOutcome{}, err
|
|
||||||
}
|
|
||||||
newOutcome := domain.CreateBetOutcome{
|
newOutcome := domain.CreateBetOutcome{
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
OddID: oddID,
|
OddID: oddID,
|
||||||
MarketID: marketID,
|
MarketID: marketID,
|
||||||
SportID: sportID,
|
SportID: int64(event.SportID),
|
||||||
HomeTeamName: event.HomeTeam,
|
HomeTeamName: event.HomeTeam,
|
||||||
AwayTeamName: event.AwayTeam,
|
AwayTeamName: event.AwayTeam,
|
||||||
MarketName: odds.MarketName,
|
MarketName: odds.MarketName,
|
||||||
|
|
@ -278,7 +274,7 @@ func (s *Service) PlaceBet(ctx context.Context, req domain.CreateBetReq, userID
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID, sportID, HomeTeam, AwayTeam string, StartTime time.Time, numMarkets int) ([]domain.CreateBetOutcome, float32, error) {
|
func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID string, 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
|
||||||
|
|
@ -328,11 +324,6 @@ func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID, sportI
|
||||||
s.logger.Error("Failed to parse odd", "error", err)
|
s.logger.Error("Failed to parse odd", "error", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sportID, err := strconv.ParseInt(sportID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Error("Failed to get sport id", "error", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
eventID, err := strconv.ParseInt(eventID, 10, 64)
|
eventID, err := strconv.ParseInt(eventID, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to get event id", "error", err)
|
s.logger.Error("Failed to get event id", "error", err)
|
||||||
|
|
@ -356,7 +347,7 @@ func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID, sportI
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
OddID: oddID,
|
OddID: oddID,
|
||||||
MarketID: marketID,
|
MarketID: marketID,
|
||||||
SportID: sportID,
|
SportID: int64(sportID),
|
||||||
HomeTeamName: HomeTeam,
|
HomeTeamName: HomeTeam,
|
||||||
AwayTeamName: AwayTeam,
|
AwayTeamName: AwayTeam,
|
||||||
MarketName: marketName,
|
MarketName: marketName,
|
||||||
|
|
@ -379,7 +370,7 @@ func (s *Service) GenerateRandomBetOutcomes(ctx context.Context, eventID, sportI
|
||||||
return newOdds, totalOdds, nil
|
return newOdds, totalOdds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) PlaceRandomBet(ctx context.Context, userID, branchID int64, leagueID, sportID domain.ValidString, firstStartTime, lastStartTime domain.ValidTime) (domain.CreateBetRes, error) {
|
func (s *Service) PlaceRandomBet(ctx context.Context, userID, branchID int64, leagueID, sportID domain.ValidInt32, firstStartTime, lastStartTime domain.ValidTime) (domain.CreateBetRes, error) {
|
||||||
|
|
||||||
// Get a unexpired event id
|
// Get a unexpired event id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ type Service interface {
|
||||||
FetchUpcomingEvents(ctx context.Context) error
|
FetchUpcomingEvents(ctx context.Context) error
|
||||||
GetAllUpcomingEvents(ctx context.Context) ([]domain.UpcomingEvent, error)
|
GetAllUpcomingEvents(ctx context.Context) ([]domain.UpcomingEvent, error)
|
||||||
GetExpiredUpcomingEvents(ctx context.Context) ([]domain.UpcomingEvent, error)
|
GetExpiredUpcomingEvents(ctx context.Context) ([]domain.UpcomingEvent, error)
|
||||||
GetPaginatedUpcomingEvents(ctx context.Context, limit domain.ValidInt64, offset domain.ValidInt64, leagueID domain.ValidString, sportID domain.ValidString, firstStartTime domain.ValidTime, lastStartTime domain.ValidTime) ([]domain.UpcomingEvent, int64, error)
|
GetPaginatedUpcomingEvents(ctx context.Context, limit domain.ValidInt64, offset domain.ValidInt64, leagueID domain.ValidInt32, sportID domain.ValidInt32, firstStartTime domain.ValidTime, lastStartTime domain.ValidTime) ([]domain.UpcomingEvent, int64, error)
|
||||||
GetUpcomingEventByID(ctx context.Context, ID string) (domain.UpcomingEvent, error)
|
GetUpcomingEventByID(ctx context.Context, ID string) (domain.UpcomingEvent, error)
|
||||||
// GetAndStoreMatchResult(ctx context.Context, eventID string) error
|
// GetAndStoreMatchResult(ctx context.Context, eventID string) error
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func (s *service) FetchLiveEvents(ctx context.Context) error {
|
||||||
name string
|
name string
|
||||||
source string
|
source string
|
||||||
}{
|
}{
|
||||||
{"https://api.b365api.com/v1/bet365/inplay?sport_id=%d&&token=%s", "bet365"},
|
{"https://api.b365api.com/v1/bet365/inplay?sport_id=%d&token=%s", "bet365"},
|
||||||
{"https://api.b365api.com/v1/betfair/sb/inplay?sport_id=%d&token=%s", "betfair"},
|
{"https://api.b365api.com/v1/betfair/sb/inplay?sport_id=%d&token=%s", "betfair"},
|
||||||
{"https://api.b365api.com/v1/1xbet/inplay?sport_id=%d&token=%s", "1xbet"},
|
{"https://api.b365api.com/v1/1xbet/inplay?sport_id=%d&token=%s", "1xbet"},
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,6 @@ func (s *service) FetchLiveEvents(ctx context.Context) error {
|
||||||
s.fetchLiveEvents(ctx, url.name, url.source)
|
s.fetchLiveEvents(ctx, url.name, url.source)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -118,17 +117,17 @@ func handleBet365prematch(body []byte, sportID int, source string) []domain.Even
|
||||||
|
|
||||||
event := domain.Event{
|
event := domain.Event{
|
||||||
ID: getString(ev["ID"]),
|
ID: getString(ev["ID"]),
|
||||||
SportID: fmt.Sprintf("%d", sportID),
|
SportID: int32(sportID),
|
||||||
MatchName: getString(ev["NA"]),
|
MatchName: getString(ev["NA"]),
|
||||||
Score: getString(ev["SS"]),
|
Score: getString(ev["SS"]),
|
||||||
MatchMinute: getInt(ev["TM"]),
|
MatchMinute: getInt(ev["TM"]),
|
||||||
TimerStatus: getString(ev["TT"]),
|
TimerStatus: getString(ev["TT"]),
|
||||||
HomeTeamID: getString(ev["HT"]),
|
HomeTeamID: getInt32(ev["HT"]),
|
||||||
AwayTeamID: getString(ev["AT"]),
|
AwayTeamID: getInt32(ev["AT"]),
|
||||||
HomeKitImage: getString(ev["K1"]),
|
HomeKitImage: getString(ev["K1"]),
|
||||||
AwayKitImage: getString(ev["K2"]),
|
AwayKitImage: getString(ev["K2"]),
|
||||||
LeagueName: getString(ev["CT"]),
|
LeagueName: getString(ev["CT"]),
|
||||||
LeagueID: getString(ev["C2"]),
|
LeagueID: getInt32(ev["C2"]),
|
||||||
LeagueCC: getString(ev["CB"]),
|
LeagueCC: getString(ev["CB"]),
|
||||||
StartTime: time.Now().UTC().Format(time.RFC3339),
|
StartTime: time.Now().UTC().Format(time.RFC3339),
|
||||||
IsLive: true,
|
IsLive: true,
|
||||||
|
|
@ -159,17 +158,14 @@ func handleBetfairprematch(body []byte, sportID int, source string) []domain.Eve
|
||||||
|
|
||||||
for _, ev := range data.Results {
|
for _, ev := range data.Results {
|
||||||
homeRaw, _ := ev["home"].(map[string]interface{})
|
homeRaw, _ := ev["home"].(map[string]interface{})
|
||||||
homeId, _ := homeRaw["id"].(string)
|
|
||||||
|
|
||||||
awayRaw, _ := ev["home"].(map[string]interface{})
|
awayRaw, _ := ev["home"].(map[string]interface{})
|
||||||
awayId, _ := awayRaw["id"].(string)
|
|
||||||
|
|
||||||
event := domain.Event{
|
event := domain.Event{
|
||||||
ID: getString(ev["id"]),
|
ID: getString(ev["id"]),
|
||||||
SportID: fmt.Sprintf("%d", sportID),
|
SportID: int32(sportID),
|
||||||
TimerStatus: getString(ev["time_status"]),
|
TimerStatus: getString(ev["time_status"]),
|
||||||
HomeTeamID: homeId,
|
HomeTeamID: getInt32(homeRaw["id"]),
|
||||||
AwayTeamID: awayId,
|
AwayTeamID: getInt32(awayRaw["id"]),
|
||||||
StartTime: time.Now().UTC().Format(time.RFC3339),
|
StartTime: time.Now().UTC().Format(time.RFC3339),
|
||||||
IsLive: true,
|
IsLive: true,
|
||||||
Status: "live",
|
Status: "live",
|
||||||
|
|
@ -249,20 +245,21 @@ func (s *service) fetchUpcomingEventsFromProvider(ctx context.Context, url, sour
|
||||||
if !slices.Contains(domain.SupportedLeagues, leagueID) {
|
if !slices.Contains(domain.SupportedLeagues, leagueID) {
|
||||||
// fmt.Printf("⚠️ Skipping league %s (%d) as it is not supported\n", ev.League.Name, leagueID)
|
// fmt.Printf("⚠️ Skipping league %s (%d) as it is not supported\n", ev.League.Name, leagueID)
|
||||||
skippedLeague = append(skippedLeague, ev.League.Name)
|
skippedLeague = append(skippedLeague, ev.League.Name)
|
||||||
continue
|
// ! for now
|
||||||
|
// continue
|
||||||
}
|
}
|
||||||
|
|
||||||
event := domain.UpcomingEvent{
|
event := domain.UpcomingEvent{
|
||||||
ID: ev.ID,
|
ID: ev.ID,
|
||||||
SportID: ev.SportID,
|
SportID: convertInt32(ev.SportID),
|
||||||
MatchName: "",
|
MatchName: "",
|
||||||
HomeTeam: ev.Home.Name,
|
HomeTeam: ev.Home.Name,
|
||||||
AwayTeam: "", // handle nil safely
|
AwayTeam: "", // handle nil safely
|
||||||
HomeTeamID: ev.Home.ID,
|
HomeTeamID: convertInt32(ev.Home.ID),
|
||||||
AwayTeamID: "",
|
AwayTeamID: 0,
|
||||||
HomeKitImage: "",
|
HomeKitImage: "",
|
||||||
AwayKitImage: "",
|
AwayKitImage: "",
|
||||||
LeagueID: ev.League.ID,
|
LeagueID: convertInt32(ev.League.ID),
|
||||||
LeagueName: ev.League.Name,
|
LeagueName: ev.League.Name,
|
||||||
LeagueCC: "",
|
LeagueCC: "",
|
||||||
StartTime: time.Unix(startUnix, 0).UTC(),
|
StartTime: time.Unix(startUnix, 0).UTC(),
|
||||||
|
|
@ -271,7 +268,7 @@ func (s *service) fetchUpcomingEventsFromProvider(ctx context.Context, url, sour
|
||||||
|
|
||||||
if ev.Away != nil {
|
if ev.Away != nil {
|
||||||
event.AwayTeam = ev.Away.Name
|
event.AwayTeam = ev.Away.Name
|
||||||
event.AwayTeamID = ev.Away.ID
|
event.AwayTeamID = convertInt32(ev.Away.ID)
|
||||||
event.MatchName = ev.Home.Name + " vs " + ev.Away.Name
|
event.MatchName = ev.Home.Name + " vs " + ev.Away.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -309,6 +306,20 @@ func getInt(v interface{}) int {
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getInt32(v interface{}) int32 {
|
||||||
|
if n, err := strconv.Atoi(getString(v)); err == nil {
|
||||||
|
return int32(n)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertInt32(num string) int32 {
|
||||||
|
if n, err := strconv.Atoi(num); err == nil {
|
||||||
|
return int32(n)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
func (s *service) GetAllUpcomingEvents(ctx context.Context) ([]domain.UpcomingEvent, error) {
|
func (s *service) GetAllUpcomingEvents(ctx context.Context) ([]domain.UpcomingEvent, error) {
|
||||||
return s.store.GetAllUpcomingEvents(ctx)
|
return s.store.GetAllUpcomingEvents(ctx)
|
||||||
}
|
}
|
||||||
|
|
@ -317,7 +328,7 @@ func (s *service) GetExpiredUpcomingEvents(ctx context.Context) ([]domain.Upcomi
|
||||||
return s.store.GetExpiredUpcomingEvents(ctx)
|
return s.store.GetExpiredUpcomingEvents(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) GetPaginatedUpcomingEvents(ctx context.Context, limit domain.ValidInt64, offset domain.ValidInt64, leagueID domain.ValidString, sportID domain.ValidString, firstStartTime domain.ValidTime, lastStartTime domain.ValidTime) ([]domain.UpcomingEvent, int64, error) {
|
func (s *service) GetPaginatedUpcomingEvents(ctx context.Context, limit domain.ValidInt64, offset domain.ValidInt64, leagueID domain.ValidInt32, sportID domain.ValidInt32, firstStartTime domain.ValidTime, lastStartTime domain.ValidTime) ([]domain.UpcomingEvent, int64, error) {
|
||||||
return s.store.GetPaginatedUpcomingEvents(ctx, limit, offset, leagueID, sportID, firstStartTime, lastStartTime)
|
return s.store.GetPaginatedUpcomingEvents(ctx, limit, offset, leagueID, sportID, firstStartTime, lastStartTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,15 @@ func New(store *repository.Store, cfg *config.Config, logger *slog.Logger) *Serv
|
||||||
func (s *ServiceImpl) FetchNonLiveOdds(ctx context.Context) error {
|
func (s *ServiceImpl) FetchNonLiveOdds(ctx context.Context) error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
errChan := make(chan error, 2)
|
errChan := make(chan error, 2)
|
||||||
wg.Add(2)
|
// wg.Add(2)
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
go func() {
|
// go func() {
|
||||||
defer wg.Done()
|
// defer wg.Done()
|
||||||
if err := s.fetchBet365Odds(ctx); err != nil {
|
// if err := s.fetchBet365Odds(ctx); err != nil {
|
||||||
errChan <- fmt.Errorf("bet365 odds fetching error: %w", err)
|
// errChan <- fmt.Errorf("bet365 odds fetching error: %w", err)
|
||||||
}
|
// }
|
||||||
}()
|
// }()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
@ -112,9 +113,7 @@ func (s *ServiceImpl) fetchBet365Odds(ctx context.Context) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sportID, err := strconv.ParseInt(event.SportID, 10, 64)
|
switch event.SportID {
|
||||||
|
|
||||||
switch sportID {
|
|
||||||
case domain.FOOTBALL:
|
case domain.FOOTBALL:
|
||||||
if err := s.parseFootball(ctx, oddsData.Results[0]); err != nil {
|
if err := s.parseFootball(ctx, oddsData.Results[0]); err != nil {
|
||||||
s.logger.Error("Error while inserting football odd")
|
s.logger.Error("Error while inserting football odd")
|
||||||
|
|
@ -142,7 +141,7 @@ func (s *ServiceImpl) fetchBet365Odds(ctx context.Context) error {
|
||||||
func (s *ServiceImpl) fetchBwinOdds(ctx context.Context) error {
|
func (s *ServiceImpl) fetchBwinOdds(ctx context.Context) error {
|
||||||
// getting odds for a specific event is not possible for bwin, most specific we can get is fetch odds on a single sport
|
// getting odds for a specific event is not possible for bwin, most specific we can get is fetch odds on a single sport
|
||||||
// so instead of having event and odds fetched separetly event will also be fetched along with the odds
|
// so instead of having event and odds fetched separetly event will also be fetched along with the odds
|
||||||
sportIds := []int{12, 7}
|
sportIds := []int{4, 12, 7}
|
||||||
for _, sportId := range sportIds {
|
for _, sportId := range sportIds {
|
||||||
url := fmt.Sprintf("https://api.b365api.com/v1/bwin/prematch?sport_id=%d&token=%s", sportId, s.config.Bet365Token)
|
url := fmt.Sprintf("https://api.b365api.com/v1/bwin/prematch?sport_id=%d&token=%s", sportId, s.config.Bet365Token)
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
|
|
@ -181,13 +180,13 @@ func (s *ServiceImpl) fetchBwinOdds(ctx context.Context) error {
|
||||||
|
|
||||||
event := domain.Event{
|
event := domain.Event{
|
||||||
ID: strconv.Itoa(getInt(res["Id"])),
|
ID: strconv.Itoa(getInt(res["Id"])),
|
||||||
SportID: strconv.Itoa(getInt(res["SportId"])),
|
SportID: int32(getInt(res["SportId"])),
|
||||||
LeagueID: strconv.Itoa(getInt(res["LeagueId"])),
|
LeagueID: int32(getInt(res["LeagueId"])),
|
||||||
LeagueName: getString(res["Leaguename"]),
|
LeagueName: getString(res["Leaguename"]),
|
||||||
HomeTeam: getString(res["HomeTeam"]),
|
HomeTeam: getString(res["HomeTeam"]),
|
||||||
HomeTeamID: strconv.Itoa(getInt(res["HomeTeamId"])),
|
HomeTeamID: int32(getInt(res["HomeTeamId"])),
|
||||||
AwayTeam: getString(res["AwayTeam"]),
|
AwayTeam: getString(res["AwayTeam"]),
|
||||||
AwayTeamID: strconv.Itoa(getInt(res["AwayTeamId"])),
|
AwayTeamID: int32(getInt(res["AwayTeamId"])),
|
||||||
StartTime: time.Now().UTC().Format(time.RFC3339),
|
StartTime: time.Now().UTC().Format(time.RFC3339),
|
||||||
TimerStatus: "1",
|
TimerStatus: "1",
|
||||||
IsLive: true,
|
IsLive: true,
|
||||||
|
|
@ -200,23 +199,25 @@ func (s *ServiceImpl) fetchBwinOdds(ctx context.Context) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, m := range getMapArray(res["Markets"]) {
|
for _, market := range []string{"Markets, optionMarkets"} {
|
||||||
name := getMap(m["name"])
|
for _, m := range getMapArray(res[market]) {
|
||||||
marketName := getString(name["value"])
|
name := getMap(m["name"])
|
||||||
|
marketName := getString(name["value"])
|
||||||
|
|
||||||
|
market := domain.Market{
|
||||||
|
EventID: event.ID,
|
||||||
|
MarketID: getString(m["id"]),
|
||||||
|
MarketCategory: getString(m["category"]),
|
||||||
|
MarketName: marketName,
|
||||||
|
Source: "bwin",
|
||||||
|
}
|
||||||
|
|
||||||
|
results := getMapArray(m["results"])
|
||||||
|
market.Odds = results
|
||||||
|
|
||||||
|
s.store.SaveNonLiveMarket(ctx, market)
|
||||||
|
|
||||||
market := domain.Market{
|
|
||||||
EventID: event.ID,
|
|
||||||
MarketID: getString(m["id"]),
|
|
||||||
MarketCategory: getString(m["category"]),
|
|
||||||
MarketName: marketName,
|
|
||||||
Source: "bwin",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results := getMapArray(m["results"])
|
|
||||||
market.Odds = results
|
|
||||||
|
|
||||||
s.store.SaveNonLiveMarket(ctx, market)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,8 @@ func (s *Service) FetchAndProcessResults(ctx context.Context) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sportID, err := strconv.ParseInt(event.SportID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Error("Sport ID is invalid", "event_id", outcome.EventID, "error", err)
|
|
||||||
isDeleted = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// TODO: optimize this because the result is being fetched for each outcome which will have the same event id but different market id
|
// TODO: optimize this because the result is being fetched for each outcome which will have the same event id but different market id
|
||||||
result, err := s.fetchResult(ctx, outcome.EventID, outcome.OddID, outcome.MarketID, sportID, outcome)
|
result, err := s.fetchResult(ctx, outcome.EventID, outcome.OddID, outcome.MarketID, int64(event.SportID), outcome)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrEventIsNotActive {
|
if err == ErrEventIsNotActive {
|
||||||
s.logger.Warn("Event is not active", "event_id", outcome.EventID, "error", err)
|
s.logger.Warn("Event is not active", "event_id", outcome.EventID, "error", err)
|
||||||
|
|
|
||||||
|
|
@ -71,18 +71,28 @@ func (h *Handler) RandomBet(c *fiber.Ctx) error {
|
||||||
userID := c.Locals("user_id").(int64)
|
userID := c.Locals("user_id").(int64)
|
||||||
// role := c.Locals("role").(domain.Role)
|
// role := c.Locals("role").(domain.Role)
|
||||||
|
|
||||||
leagueIDQuery := c.Query("league_id")
|
leagueIDQuery, err := strconv.Atoi(c.Query("league_id"))
|
||||||
sportIDQuery := c.Query("sport_id")
|
if err != nil {
|
||||||
|
h.logger.Error("invalid league id", "error", err)
|
||||||
|
return response.WriteJSON(c, fiber.StatusBadRequest, "invalid league id", nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
sportIDQuery, err := strconv.Atoi(c.Query("sport_id"))
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Error("invalid sport id", "error", err)
|
||||||
|
return response.WriteJSON(c, fiber.StatusBadRequest, "invalid sport id", nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
firstStartTimeQuery := c.Query("first_start_time")
|
firstStartTimeQuery := c.Query("first_start_time")
|
||||||
lastStartTimeQuery := c.Query("last_start_time")
|
lastStartTimeQuery := c.Query("last_start_time")
|
||||||
|
|
||||||
leagueID := domain.ValidString{
|
leagueID := domain.ValidInt32{
|
||||||
Value: leagueIDQuery,
|
Value: int32(leagueIDQuery),
|
||||||
Valid: leagueIDQuery != "",
|
Valid: leagueIDQuery != 0,
|
||||||
}
|
}
|
||||||
sportID := domain.ValidString{
|
sportID := domain.ValidInt32{
|
||||||
Value: sportIDQuery,
|
Value: int32(sportIDQuery),
|
||||||
Valid: sportIDQuery != "",
|
Valid: sportIDQuery != 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstStartTime domain.ValidTime
|
var firstStartTime domain.ValidTime
|
||||||
|
|
@ -122,7 +132,6 @@ func (h *Handler) RandomBet(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var res domain.CreateBetRes
|
var res domain.CreateBetRes
|
||||||
var err error
|
|
||||||
for i := 0; i < int(req.NumberOfBets); i++ {
|
for i := 0; i < int(req.NumberOfBets); i++ {
|
||||||
res, err = h.betSvc.PlaceRandomBet(c.Context(), userID, req.BranchID, leagueID, sportID, firstStartTime, lastStartTime)
|
res, err = h.betSvc.PlaceRandomBet(c.Context(), userID, req.BranchID, leagueID, sportID, firstStartTime, lastStartTime)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,18 +107,27 @@ func (h *Handler) GetRawOddsByMarketID(c *fiber.Ctx) error {
|
||||||
func (h *Handler) GetAllUpcomingEvents(c *fiber.Ctx) error {
|
func (h *Handler) GetAllUpcomingEvents(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)
|
||||||
leagueIDQuery := c.Query("league_id")
|
leagueIDQuery, err := strconv.Atoi(c.Query("league_id"))
|
||||||
sportIDQuery := c.Query("sport_id")
|
if err != nil {
|
||||||
|
h.logger.Error("invalid league id", "error", err)
|
||||||
|
return response.WriteJSON(c, fiber.StatusBadRequest, "invalid league id", nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
sportIDQuery, err := strconv.Atoi(c.Query("sport_id"))
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Error("invalid sport id", "error", err)
|
||||||
|
return response.WriteJSON(c, fiber.StatusBadRequest, "invalid sport id", nil, nil)
|
||||||
|
}
|
||||||
firstStartTimeQuery := c.Query("first_start_time")
|
firstStartTimeQuery := c.Query("first_start_time")
|
||||||
lastStartTimeQuery := c.Query("last_start_time")
|
lastStartTimeQuery := c.Query("last_start_time")
|
||||||
|
|
||||||
leagueID := domain.ValidString{
|
leagueID := domain.ValidInt32{
|
||||||
Value: leagueIDQuery,
|
Value: int32(leagueIDQuery),
|
||||||
Valid: leagueIDQuery != "",
|
Valid: leagueIDQuery != 0,
|
||||||
}
|
}
|
||||||
sportID := domain.ValidString{
|
sportID := domain.ValidInt32{
|
||||||
Value: sportIDQuery,
|
Value: int32(sportIDQuery),
|
||||||
Valid: sportIDQuery != "",
|
Valid: sportIDQuery != 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstStartTime domain.ValidTime
|
var firstStartTime domain.ValidTime
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user