62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
func (s *Store) SaveLeague(ctx context.Context, l domain.League) error {
|
|
return s.queries.InsertLeague(ctx, dbgen.InsertLeagueParams{
|
|
ID: l.ID,
|
|
Name: l.Name,
|
|
CountryCode: pgtype.Text{String: l.CountryCode, Valid: true},
|
|
Bet365ID: pgtype.Int4{Int32: l.Bet365ID, Valid: true},
|
|
IsActive: pgtype.Bool{Bool: l.IsActive, Valid: true},
|
|
})
|
|
}
|
|
|
|
func (s *Store) GetSupportedLeagues(ctx context.Context) ([]domain.League, error) {
|
|
leagues, err := s.queries.GetSupportedLeagues(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
supportedLeagues := make([]domain.League, len(leagues))
|
|
for i, league := range leagues {
|
|
supportedLeagues[i] = domain.League{
|
|
ID: league.ID,
|
|
Name: league.Name,
|
|
CountryCode: league.CountryCode.String,
|
|
Bet365ID: league.Bet365ID.Int32,
|
|
IsActive: league.IsActive.Bool,
|
|
}
|
|
}
|
|
return supportedLeagues, nil
|
|
}
|
|
|
|
func (s *Store) CheckLeagueSupport(ctx context.Context, leagueID int64) (bool, error) {
|
|
return s.queries.CheckLeagueSupport(ctx, leagueID)
|
|
}
|
|
|
|
// TODO: change to only take league id instad of the whole league
|
|
func (s *Store) SetLeagueActive(ctx context.Context, l domain.League) error {
|
|
return s.queries.UpdateLeague(ctx, dbgen.UpdateLeagueParams{
|
|
Name: l.Name,
|
|
CountryCode: pgtype.Text{String: l.CountryCode, Valid: true},
|
|
Bet365ID: pgtype.Int4{Int32: l.Bet365ID, Valid: true},
|
|
IsActive: pgtype.Bool{Bool: true, Valid: true},
|
|
})
|
|
}
|
|
|
|
func (s *Store) SetLeagueInActive(ctx context.Context, l domain.League) error {
|
|
return s.queries.UpdateLeague(ctx, dbgen.UpdateLeagueParams{
|
|
Name: l.Name,
|
|
CountryCode: pgtype.Text{String: l.CountryCode, Valid: true},
|
|
Bet365ID: pgtype.Int4{Int32: l.Bet365ID, Valid: true},
|
|
IsActive: pgtype.Bool{Bool: false, Valid: true},
|
|
})
|
|
}
|