73 lines
2.2 KiB
Go
73 lines
2.2 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,
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return domain.ConvertDBLeagueWithSettings(l), 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))
|
|
}
|