65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
func (s *Store) SaveNonLiveOdd(ctx context.Context, o domain.OddsRecord) error {
|
|
params := dbgen.InsertNonLiveOddParams{
|
|
EventID: pgtype.Text{
|
|
String: o.EventID,
|
|
Valid: o.EventID != "",
|
|
},
|
|
MarketType: o.MarketType,
|
|
Header: pgtype.Text{
|
|
String: o.Header,
|
|
Valid: o.Header != "",
|
|
},
|
|
Name: pgtype.Text{
|
|
String: o.Name,
|
|
Valid: o.Name != "",
|
|
},
|
|
OddsValue: pgtype.Float8{
|
|
Float64: o.OddsValue,
|
|
Valid: true,
|
|
},
|
|
Handicap: pgtype.Text{
|
|
String: o.Handicap,
|
|
Valid: o.Handicap != "",
|
|
},
|
|
Section: o.Section,
|
|
Category: pgtype.Text{
|
|
String: o.Category,
|
|
Valid: o.Category != "",
|
|
},
|
|
MarketID: pgtype.Text{
|
|
String: o.MarketID,
|
|
Valid: o.MarketID != "",
|
|
},
|
|
RawEventID: pgtype.Text{
|
|
String: o.RawEventID,
|
|
Valid: o.RawEventID != "",
|
|
},
|
|
}
|
|
|
|
err := s.queries.InsertNonLiveOdd(ctx, params)
|
|
|
|
if err != nil {
|
|
fmt.Printf("❌ Failed to insert odd: event_id=%s | market=%s | odds=%.3f | error=%v\n",
|
|
o.EventID, o.MarketType, o.OddsValue, err)
|
|
} else {
|
|
fmt.Printf("✅ Stored: event_id=%s | market=%s | odds=%.3f\n", o.EventID, o.MarketType, o.OddsValue)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (s *Store) GetUpcomingEventIDs(ctx context.Context) ([]string, error) {
|
|
return s.queries.GetUpcomingEventIDs(ctx)
|
|
}
|