- Updated league handling to ensure valid page size checks and improved error handling for sport ID parsing. - Introduced new endpoint to update global league settings with comprehensive validation and error logging. - Refactored odds settings management, including saving, removing, and updating odds settings with enhanced validation. - Added tenant slug retrieval by token, ensuring proper user and company validation. - Improved middleware to check for active company status and adjusted route permissions for various endpoints. - Added SQL script to fix auto-increment desynchronization across multiple tables.
92 lines
2.8 KiB
Go
92 lines
2.8 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.SaveLeagueSettings(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, int64, 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, 0, err
|
|
}
|
|
|
|
total, err := s.queries.GetTotalLeaguesWithSettings(ctx, dbgen.GetTotalLeaguesWithSettingsParams{
|
|
Query: filter.Query.ToPG(),
|
|
CompanyID: companyID,
|
|
CountryCode: filter.CountryCode.ToPG(),
|
|
SportID: filter.SportID.ToPG(),
|
|
IsFeatured: filter.IsFeatured.ToPG(),
|
|
IsActive: filter.IsActive.ToPG(),
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return domain.ConvertDBLeagueWithSettings(l), total, 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))
|
|
}
|
|
|
|
func (s *Store) UpdateGlobalLeagueSettings(ctx context.Context, league domain.UpdateGlobalLeagueSettings) error {
|
|
return s.queries.UpdateGlobalLeagueSettings(ctx, domain.ConvertUpdateGlobalLeagueSetting(league))
|
|
}
|