From 192cdb3b263037bd4ca3ba854170e85f3eaf95c8 Mon Sep 17 00:00:00 2001 From: Samuel Tariku Date: Wed, 13 Aug 2025 22:49:20 +0300 Subject: [PATCH] fix: minor fixes --- db/migrations/000001_fortune.up.sql | 22 ------ gen/db/events.sql.go | 118 +++++++++++++++------------- gen/db/models.go | 70 +++++++++++------ internal/web_server/cron.go | 20 ++--- 4 files changed, 117 insertions(+), 113 deletions(-) diff --git a/db/migrations/000001_fortune.up.sql b/db/migrations/000001_fortune.up.sql index 8c29c37..c9a0fd2 100644 --- a/db/migrations/000001_fortune.up.sql +++ b/db/migrations/000001_fortune.up.sql @@ -19,7 +19,6 @@ CREATE TABLE IF NOT EXISTS users ( OR phone_number IS NOT NULL ) ); - CREATE TABLE IF NOT EXISTS wallets ( id BIGSERIAL PRIMARY KEY, balance BIGINT NOT NULL DEFAULT 0, @@ -32,7 +31,6 @@ CREATE TABLE IF NOT EXISTS wallets ( created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); - CREATE TABLE refresh_tokens ( id BIGSERIAL PRIMARY KEY, user_id BIGINT NOT NULL, @@ -42,26 +40,6 @@ CREATE TABLE refresh_tokens ( revoked BOOLEAN DEFAULT FALSE NOT NULL, CONSTRAINT unique_token UNIQUE (token) ); - - -CREATE TABLE direct_deposits ( - id BIGSERIAL PRIMARY KEY, - customer_id BIGINT NOT NULL REFERENCES users(id), - wallet_id BIGINT NOT NULL REFERENCES wallets(id), - amount NUMERIC(15, 2) NOT NULL, - bank_reference TEXT NOT NULL, - sender_account TEXT NOT NULL, - status TEXT NOT NULL CHECK (status IN ('pending', 'completed', 'rejected')), - created_at TIMESTAMP NOT NULL DEFAULT NOW(), - verified_by BIGINT REFERENCES users(id), - verification_notes TEXT, - verified_at TIMESTAMP -); - -CREATE INDEX idx_direct_deposits_status ON direct_deposits(status); -CREATE INDEX idx_direct_deposits_customer ON direct_deposits(customer_id); -CREATE INDEX idx_direct_deposits_reference ON direct_deposits(bank_reference); - ----- CREATE TABLE otps ( id BIGSERIAL PRIMARY KEY, diff --git a/gen/db/events.sql.go b/gen/db/events.sql.go index 423354b..8e1978a 100644 --- a/gen/db/events.sql.go +++ b/gen/db/events.sql.go @@ -22,7 +22,7 @@ func (q *Queries) DeleteEvent(ctx context.Context, id string) error { } const GetAllUpcomingEvents = `-- name: GetAllUpcomingEvents :many -SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, league_cc, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, is_featured, is_monitored, is_active +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, league_cc, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, is_featured, is_monitored, winning_upper_limit, is_active FROM events WHERE start_time > now() AND is_live = false @@ -64,6 +64,7 @@ func (q *Queries) GetAllUpcomingEvents(ctx context.Context) ([]Event, error) { &i.Source, &i.IsFeatured, &i.IsMonitored, + &i.WinningUpperLimit, &i.IsActive, ); err != nil { return nil, err @@ -77,7 +78,7 @@ func (q *Queries) GetAllUpcomingEvents(ctx context.Context) ([]Event, error) { } const GetExpiredUpcomingEvents = `-- name: GetExpiredUpcomingEvents :many -SELECT events.id, events.sport_id, events.match_name, events.home_team, events.away_team, events.home_team_id, events.away_team_id, events.home_kit_image, events.away_kit_image, events.league_id, events.league_name, events.league_cc, events.start_time, events.score, events.match_minute, events.timer_status, events.added_time, events.match_period, events.is_live, events.status, events.fetched_at, events.source, events.is_featured, events.is_monitored, events.is_active, +SELECT events.id, events.sport_id, events.match_name, events.home_team, events.away_team, events.home_team_id, events.away_team_id, events.home_kit_image, events.away_kit_image, events.league_id, events.league_name, events.league_cc, events.start_time, events.score, events.match_minute, events.timer_status, events.added_time, events.match_period, events.is_live, events.status, events.fetched_at, events.source, events.is_featured, events.is_monitored, events.winning_upper_limit, events.is_active, leagues.country_code as league_cc FROM events LEFT JOIN leagues ON leagues.id = league_id @@ -90,32 +91,33 @@ ORDER BY start_time ASC ` type GetExpiredUpcomingEventsRow struct { - ID string `json:"id"` - SportID pgtype.Int4 `json:"sport_id"` - MatchName pgtype.Text `json:"match_name"` - HomeTeam pgtype.Text `json:"home_team"` - AwayTeam pgtype.Text `json:"away_team"` - HomeTeamID pgtype.Int4 `json:"home_team_id"` - AwayTeamID pgtype.Int4 `json:"away_team_id"` - HomeKitImage pgtype.Text `json:"home_kit_image"` - AwayKitImage pgtype.Text `json:"away_kit_image"` - LeagueID pgtype.Int4 `json:"league_id"` - LeagueName pgtype.Text `json:"league_name"` - LeagueCc pgtype.Text `json:"league_cc"` - StartTime pgtype.Timestamp `json:"start_time"` - Score pgtype.Text `json:"score"` - MatchMinute pgtype.Int4 `json:"match_minute"` - TimerStatus pgtype.Text `json:"timer_status"` - AddedTime pgtype.Int4 `json:"added_time"` - MatchPeriod pgtype.Int4 `json:"match_period"` - IsLive pgtype.Bool `json:"is_live"` - Status pgtype.Text `json:"status"` - FetchedAt pgtype.Timestamp `json:"fetched_at"` - Source pgtype.Text `json:"source"` - IsFeatured bool `json:"is_featured"` - IsMonitored bool `json:"is_monitored"` - IsActive bool `json:"is_active"` - LeagueCc_2 pgtype.Text `json:"league_cc_2"` + ID string `json:"id"` + SportID pgtype.Int4 `json:"sport_id"` + MatchName pgtype.Text `json:"match_name"` + HomeTeam pgtype.Text `json:"home_team"` + AwayTeam pgtype.Text `json:"away_team"` + HomeTeamID pgtype.Int4 `json:"home_team_id"` + AwayTeamID pgtype.Int4 `json:"away_team_id"` + HomeKitImage pgtype.Text `json:"home_kit_image"` + AwayKitImage pgtype.Text `json:"away_kit_image"` + LeagueID pgtype.Int4 `json:"league_id"` + LeagueName pgtype.Text `json:"league_name"` + LeagueCc pgtype.Text `json:"league_cc"` + StartTime pgtype.Timestamp `json:"start_time"` + Score pgtype.Text `json:"score"` + MatchMinute pgtype.Int4 `json:"match_minute"` + TimerStatus pgtype.Text `json:"timer_status"` + AddedTime pgtype.Int4 `json:"added_time"` + MatchPeriod pgtype.Int4 `json:"match_period"` + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` + FetchedAt pgtype.Timestamp `json:"fetched_at"` + Source pgtype.Text `json:"source"` + IsFeatured bool `json:"is_featured"` + IsMonitored bool `json:"is_monitored"` + WinningUpperLimit int32 `json:"winning_upper_limit"` + IsActive bool `json:"is_active"` + LeagueCc_2 pgtype.Text `json:"league_cc_2"` } func (q *Queries) GetExpiredUpcomingEvents(ctx context.Context, status pgtype.Text) ([]GetExpiredUpcomingEventsRow, error) { @@ -152,6 +154,7 @@ func (q *Queries) GetExpiredUpcomingEvents(ctx context.Context, status pgtype.Te &i.Source, &i.IsFeatured, &i.IsMonitored, + &i.WinningUpperLimit, &i.IsActive, &i.LeagueCc_2, ); err != nil { @@ -166,7 +169,7 @@ func (q *Queries) GetExpiredUpcomingEvents(ctx context.Context, status pgtype.Te } const GetPaginatedUpcomingEvents = `-- name: GetPaginatedUpcomingEvents :many -SELECT events.id, events.sport_id, events.match_name, events.home_team, events.away_team, events.home_team_id, events.away_team_id, events.home_kit_image, events.away_kit_image, events.league_id, events.league_name, events.league_cc, events.start_time, events.score, events.match_minute, events.timer_status, events.added_time, events.match_period, events.is_live, events.status, events.fetched_at, events.source, events.is_featured, events.is_monitored, events.is_active, +SELECT events.id, events.sport_id, events.match_name, events.home_team, events.away_team, events.home_team_id, events.away_team_id, events.home_kit_image, events.away_kit_image, events.league_id, events.league_name, events.league_cc, events.start_time, events.score, events.match_minute, events.timer_status, events.added_time, events.match_period, events.is_live, events.status, events.fetched_at, events.source, events.is_featured, events.is_monitored, events.winning_upper_limit, events.is_active, leagues.country_code as league_cc FROM events LEFT JOIN leagues ON leagues.id = league_id @@ -219,32 +222,33 @@ type GetPaginatedUpcomingEventsParams struct { } type GetPaginatedUpcomingEventsRow struct { - ID string `json:"id"` - SportID pgtype.Int4 `json:"sport_id"` - MatchName pgtype.Text `json:"match_name"` - HomeTeam pgtype.Text `json:"home_team"` - AwayTeam pgtype.Text `json:"away_team"` - HomeTeamID pgtype.Int4 `json:"home_team_id"` - AwayTeamID pgtype.Int4 `json:"away_team_id"` - HomeKitImage pgtype.Text `json:"home_kit_image"` - AwayKitImage pgtype.Text `json:"away_kit_image"` - LeagueID pgtype.Int4 `json:"league_id"` - LeagueName pgtype.Text `json:"league_name"` - LeagueCc pgtype.Text `json:"league_cc"` - StartTime pgtype.Timestamp `json:"start_time"` - Score pgtype.Text `json:"score"` - MatchMinute pgtype.Int4 `json:"match_minute"` - TimerStatus pgtype.Text `json:"timer_status"` - AddedTime pgtype.Int4 `json:"added_time"` - MatchPeriod pgtype.Int4 `json:"match_period"` - IsLive pgtype.Bool `json:"is_live"` - Status pgtype.Text `json:"status"` - FetchedAt pgtype.Timestamp `json:"fetched_at"` - Source pgtype.Text `json:"source"` - IsFeatured bool `json:"is_featured"` - IsMonitored bool `json:"is_monitored"` - IsActive bool `json:"is_active"` - LeagueCc_2 pgtype.Text `json:"league_cc_2"` + ID string `json:"id"` + SportID pgtype.Int4 `json:"sport_id"` + MatchName pgtype.Text `json:"match_name"` + HomeTeam pgtype.Text `json:"home_team"` + AwayTeam pgtype.Text `json:"away_team"` + HomeTeamID pgtype.Int4 `json:"home_team_id"` + AwayTeamID pgtype.Int4 `json:"away_team_id"` + HomeKitImage pgtype.Text `json:"home_kit_image"` + AwayKitImage pgtype.Text `json:"away_kit_image"` + LeagueID pgtype.Int4 `json:"league_id"` + LeagueName pgtype.Text `json:"league_name"` + LeagueCc pgtype.Text `json:"league_cc"` + StartTime pgtype.Timestamp `json:"start_time"` + Score pgtype.Text `json:"score"` + MatchMinute pgtype.Int4 `json:"match_minute"` + TimerStatus pgtype.Text `json:"timer_status"` + AddedTime pgtype.Int4 `json:"added_time"` + MatchPeriod pgtype.Int4 `json:"match_period"` + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` + FetchedAt pgtype.Timestamp `json:"fetched_at"` + Source pgtype.Text `json:"source"` + IsFeatured bool `json:"is_featured"` + IsMonitored bool `json:"is_monitored"` + WinningUpperLimit int32 `json:"winning_upper_limit"` + IsActive bool `json:"is_active"` + LeagueCc_2 pgtype.Text `json:"league_cc_2"` } func (q *Queries) GetPaginatedUpcomingEvents(ctx context.Context, arg GetPaginatedUpcomingEventsParams) ([]GetPaginatedUpcomingEventsRow, error) { @@ -291,6 +295,7 @@ func (q *Queries) GetPaginatedUpcomingEvents(ctx context.Context, arg GetPaginat &i.Source, &i.IsFeatured, &i.IsMonitored, + &i.WinningUpperLimit, &i.IsActive, &i.LeagueCc_2, ); err != nil { @@ -367,7 +372,7 @@ func (q *Queries) GetTotalEvents(ctx context.Context, arg GetTotalEventsParams) } 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, league_cc, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, is_featured, is_monitored, is_active +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, league_cc, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, is_featured, is_monitored, winning_upper_limit, is_active FROM events WHERE id = $1 AND is_live = false @@ -403,6 +408,7 @@ func (q *Queries) GetUpcomingByID(ctx context.Context, id string) (Event, error) &i.Source, &i.IsFeatured, &i.IsMonitored, + &i.WinningUpperLimit, &i.IsActive, ) return i, err diff --git a/gen/db/models.go b/gen/db/models.go index f9cc71c..fa26879 100644 --- a/gen/db/models.go +++ b/gen/db/models.go @@ -208,6 +208,16 @@ type Company struct { UpdatedAt pgtype.Timestamp `json:"updated_at"` } +type CustomOdd struct { + ID int64 `json:"id"` + OddID int64 `json:"odd_id"` + RawOddID int64 `json:"raw_odd_id"` + MarketID string `json:"market_id"` + EventID string `json:"event_id"` + OddValue float64 `json:"odd_value"` + CreatedAt pgtype.Timestamp `json:"created_at"` +} + type CustomerWallet struct { ID int64 `json:"id"` CustomerID int64 `json:"customer_id"` @@ -248,32 +258,42 @@ type DirectDeposit struct { VerifiedAt pgtype.Timestamp `json:"verified_at"` } +type DisabledOdd struct { + ID int64 `json:"id"` + OddID int64 `json:"odd_id"` + RawOddID int64 `json:"raw_odd_id"` + MarketID string `json:"market_id"` + EventID string `json:"event_id"` + CreatedAt pgtype.Timestamp `json:"created_at"` +} + type Event struct { - ID string `json:"id"` - SportID pgtype.Int4 `json:"sport_id"` - MatchName pgtype.Text `json:"match_name"` - HomeTeam pgtype.Text `json:"home_team"` - AwayTeam pgtype.Text `json:"away_team"` - HomeTeamID pgtype.Int4 `json:"home_team_id"` - AwayTeamID pgtype.Int4 `json:"away_team_id"` - HomeKitImage pgtype.Text `json:"home_kit_image"` - AwayKitImage pgtype.Text `json:"away_kit_image"` - LeagueID pgtype.Int4 `json:"league_id"` - LeagueName pgtype.Text `json:"league_name"` - LeagueCc pgtype.Text `json:"league_cc"` - StartTime pgtype.Timestamp `json:"start_time"` - Score pgtype.Text `json:"score"` - MatchMinute pgtype.Int4 `json:"match_minute"` - TimerStatus pgtype.Text `json:"timer_status"` - AddedTime pgtype.Int4 `json:"added_time"` - MatchPeriod pgtype.Int4 `json:"match_period"` - IsLive pgtype.Bool `json:"is_live"` - Status pgtype.Text `json:"status"` - FetchedAt pgtype.Timestamp `json:"fetched_at"` - Source pgtype.Text `json:"source"` - IsFeatured bool `json:"is_featured"` - IsMonitored bool `json:"is_monitored"` - IsActive bool `json:"is_active"` + ID string `json:"id"` + SportID pgtype.Int4 `json:"sport_id"` + MatchName pgtype.Text `json:"match_name"` + HomeTeam pgtype.Text `json:"home_team"` + AwayTeam pgtype.Text `json:"away_team"` + HomeTeamID pgtype.Int4 `json:"home_team_id"` + AwayTeamID pgtype.Int4 `json:"away_team_id"` + HomeKitImage pgtype.Text `json:"home_kit_image"` + AwayKitImage pgtype.Text `json:"away_kit_image"` + LeagueID pgtype.Int4 `json:"league_id"` + LeagueName pgtype.Text `json:"league_name"` + LeagueCc pgtype.Text `json:"league_cc"` + StartTime pgtype.Timestamp `json:"start_time"` + Score pgtype.Text `json:"score"` + MatchMinute pgtype.Int4 `json:"match_minute"` + TimerStatus pgtype.Text `json:"timer_status"` + AddedTime pgtype.Int4 `json:"added_time"` + MatchPeriod pgtype.Int4 `json:"match_period"` + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` + FetchedAt pgtype.Timestamp `json:"fetched_at"` + Source pgtype.Text `json:"source"` + IsFeatured bool `json:"is_featured"` + IsMonitored bool `json:"is_monitored"` + WinningUpperLimit int32 `json:"winning_upper_limit"` + IsActive bool `json:"is_active"` } type EventHistory struct { diff --git a/internal/web_server/cron.go b/internal/web_server/cron.go index df8b6f0..b2efabb 100644 --- a/internal/web_server/cron.go +++ b/internal/web_server/cron.go @@ -28,65 +28,65 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S // { // spec: "0 0 * * * *", // Every 1 hour // task: func() { - // mongoLogger.Info("Began fetching upcoming events") + // mongoLogger.Info("Began fetching upcoming events cron task") // if err := eventService.FetchUpcomingEvents(context.Background()); err != nil { // mongoLogger.Error("Failed to fetch upcoming events", // zap.Error(err), // ) // } else { - // mongoLogger.Info("Successfully fetched upcoming events") + // mongoLogger.Info("Completed fetching upcoming events without errors") // } // }, // }, // { // spec: "0 0 * * * *", // Every 1 hour (since its takes that long to fetch all the events) // task: func() { - // mongoLogger.Info("Began fetching non live odds") + // mongoLogger.Info("Began fetching non live odds cron task") // if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil { // mongoLogger.Error("Failed to fetch non live odds", // zap.Error(err), // ) // } else { - // mongoLogger.Info("Successfully fetched non live odds") + // mongoLogger.Info("Completed fetching non live odds without errors") // } // }, // }, { spec: "0 */5 * * * *", // Every 5 Minutes task: func() { - mongoLogger.Info("Began updating all expired events status") + mongoLogger.Info("Began update all expired events status cron task") if _, err := resultService.CheckAndUpdateExpiredEvents(context.Background()); err != nil { mongoLogger.Error("Failed to update expired events status", zap.Error(err), ) } else { - mongoLogger.Info("Successfully updated expired events") + mongoLogger.Info("Completed expired events without errors") } }, }, // { // spec: "0 */15 * * * *", // Every 15 Minutes // task: func() { - // mongoLogger.Info("Fetching results for upcoming events") + // mongoLogger.Info("Began fetching results for upcoming events cron task") // if err := resultService.FetchAndProcessResults(context.Background()); err != nil { // mongoLogger.Error("Failed to process result", // zap.Error(err), // ) // } else { - // mongoLogger.Info("Successfully processed all event result outcomes") + // mongoLogger.Info("Completed processing all event result outcomes without errors") // } // }, // }, { spec: "0 0 * * * *", // Every Day task: func() { - mongoLogger.Info("Send daily result notification") + mongoLogger.Info("Began Send daily result notification cron task") if err := resultService.CheckAndSendResultNotifications(context.Background(), time.Now().Add(-24*time.Hour)); err != nil { mongoLogger.Error("Failed to process result", zap.Error(err), ) } else { - mongoLogger.Info("Successfully processed all event result outcomes") + mongoLogger.Info("Completed sending daily result notification without errors") } }, },