99 lines
2.9 KiB
Go
99 lines
2.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, league domain.CreateLeague) error {
|
|
return s.queries.InsertLeague(ctx, domain.ConvertCreateLeague(league))
|
|
}
|
|
|
|
func (s *Store) SaveLeagueSettings(ctx context.Context, leagueSettings domain.CreateLeagueSettings) error {
|
|
return s.queries.InsertLeagueSettings(ctx, domain.ConvertCreateLeagueSettings(leagueSettings))
|
|
}
|
|
|
|
func (s *Store) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague, error) {
|
|
l, err := s.queries.GetAllLeagues(ctx, dbgen.GetAllLeaguesParams{
|
|
Query: filter.Query.ToPG(),
|
|
CountryCode: filter.CountryCode.ToPG(),
|
|
SportID: filter.SportID.ToPG(),
|
|
Limit: pgtype.Int4{
|
|
Int32: int32(filter.Limit.Value),
|
|
Valid: filter.Limit.Valid,
|
|
},
|
|
Offset: pgtype.Int4{
|
|
Int32: int32(filter.Offset.Value * filter.Limit.Value),
|
|
Valid: filter.Offset.Valid,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return domain.ConvertDBBaseLeagues(l), nil
|
|
}
|
|
|
|
func (s *Store) GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, error) {
|
|
l, err := s.queries.GetAllLeaguesWithSettings(ctx, dbgen.GetAllLeaguesWithSettingsParams{
|
|
Query: filter.Query.ToPG(),
|
|
CompanyID: companyID,
|
|
CountryCode: filter.CountryCode.ToPG(),
|
|
SportID: filter.SportID.ToPG(),
|
|
Limit: pgtype.Int4{
|
|
Int32: int32(filter.Limit.Value),
|
|
Valid: filter.Limit.Valid,
|
|
},
|
|
Offset: pgtype.Int4{
|
|
Int32: int32(filter.Offset.Value * filter.Limit.Value),
|
|
Valid: filter.Offset.Valid,
|
|
},
|
|
IsFeatured: filter.IsFeatured.ToPG(),
|
|
IsActive: filter.IsActive.ToPG(),
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := make([]domain.LeagueWithSettings, len(l))
|
|
for i, league := range l {
|
|
result[i] = domain.LeagueWithSettings{
|
|
ID: league.ID,
|
|
Name: league.Name,
|
|
CompanyID: league.CompanyID.Int64,
|
|
CountryCode: domain.ValidString{
|
|
Value: league.CountryCode.String,
|
|
Valid: league.CountryCode.Valid,
|
|
},
|
|
Bet365ID: domain.ValidInt32{
|
|
Value: league.Bet365ID.Int32,
|
|
Valid: league.Bet365ID.Valid,
|
|
},
|
|
IsActive: league.IsActive,
|
|
SportID: league.SportID,
|
|
IsFeatured: league.IsFeatured,
|
|
UpdatedAt: league.UpdatedAt.Time,
|
|
|
|
DefaultIsActive: league.DefaultIsActive,
|
|
DefaultIsFeatured: league.DefaultIsFeatured,
|
|
}
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func (s *Store) CheckLeagueSupport(ctx context.Context, leagueID int64, companyID int64) (bool, error) {
|
|
return s.queries.CheckLeagueSupport(ctx, dbgen.CheckLeagueSupportParams{
|
|
LeagueID: leagueID,
|
|
CompanyID: companyID,
|
|
})
|
|
}
|
|
|
|
func (s *Store) UpdateLeague(ctx context.Context, league domain.UpdateLeague) error {
|
|
return s.queries.UpdateLeague(ctx, domain.ConvertUpdateLeague(league))
|
|
}
|