diff --git a/db/migrations/000001_fortune.up.sql b/db/migrations/000001_fortune.up.sql index 75f2ed2..20dfd81 100644 --- a/db/migrations/000001_fortune.up.sql +++ b/db/migrations/000001_fortune.up.sql @@ -514,7 +514,7 @@ CREATE TABLE IF NOT EXISTS raffle_tickets ( id SERIAL PRIMARY KEY, raffle_id INT NOT NULL REFERENCES raffles(id) ON DELETE CASCADE, user_id INT NOT NULL, - is_active BOOL DEFAULT true, + is_active BOOL DEFAULT true ); CREATE TABLE IF NOT EXISTS raffle_winners ( id SERIAL PRIMARY KEY, @@ -737,4 +737,4 @@ ADD CONSTRAINT fk_event_settings_company FOREIGN KEY (company_id) REFERENCES com ADD CONSTRAINT fk_event_settings_event FOREIGN KEY (event_id) REFERENCES events (id) ON DELETE CASCADE; ALTER TABLE company_odd_settings ADD CONSTRAINT fk_odds_settings_company FOREIGN KEY (company_id) REFERENCES companies (id) ON DELETE CASCADE, - ADD CONSTRAINT fk_odds_settings_odds_market FOREIGN KEY (odds_market_id) REFERENCES odds_market (id) ON DELETE CASCADE; + ADD CONSTRAINT fk_odds_settings_odds_market FOREIGN KEY (odds_market_id) REFERENCES odds_market (id) ON DELETE CASCADE; \ No newline at end of file diff --git a/db/query/events.sql b/db/query/events.sql index 61f5a86..ba80192 100644 --- a/db/query/events.sql +++ b/db/query/events.sql @@ -187,7 +187,13 @@ WHERE is_live = false ) AND ( ces.is_featured = sqlc.narg('is_featured') + OR e.default_is_featured = sqlc.narg('is_featured') OR sqlc.narg('is_featured') IS NULL + ) + AND ( + ces.is_active = sqlc.narg('is_active') + OR e.default_is_active = sqlc.narg('is_active') + OR sqlc.narg('is_active') IS NULL ); -- name: GetEventsWithSettings :many SELECT e.*, @@ -231,10 +237,17 @@ WHERE start_time > now() AND ( l.country_code = sqlc.narg('country_code') OR sqlc.narg('country_code') IS NULL - ) AND ( - ces.is_featured = sqlc.narg('is_featured') - OR sqlc.narg('is_featured') IS NULL -) + ) + AND ( + ces.is_featured = sqlc.narg('is_featured') + OR e.default_is_featured = sqlc.narg('is_featured') + OR sqlc.narg('is_featured') IS NULL + ) + AND ( + ces.is_active = sqlc.narg('is_active') + OR e.default_is_active = sqlc.narg('is_active') + OR sqlc.narg('is_active') IS NULL + ) ORDER BY start_time ASC LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset'); -- name: GetUpcomingByID :one diff --git a/db/query/leagues.sql b/db/query/leagues.sql index 21765b9..476c3e8 100644 --- a/db/query/leagues.sql +++ b/db/query/leagues.sql @@ -42,14 +42,11 @@ WHERE ( ) ORDER BY name ASC LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset'); --- name: GetAllLeaguesWithSettings :many -SELECT l.*, - cls.company_id, - COALESCE(cls.is_active, l.default_is_active) AS is_active, - COALESCE(cls.is_featured, l.default_is_featured) AS is_featured, - cls.updated_at +-- name: GetTotalLeaguesWithSettings :one +SELECT COUNT(*) FROM leagues l - LEFT JOIN company_league_settings cls ON l.id = cls.league_id AND company_id = $1 + LEFT JOIN company_league_settings cls ON l.id = cls.league_id + AND company_id = $1 WHERE ( country_code = sqlc.narg('country_code') OR sqlc.narg('country_code') IS NULL @@ -60,10 +57,43 @@ WHERE ( ) AND ( is_active = sqlc.narg('is_active') + OR default_is_active = sqlc.narg('is_active') OR sqlc.narg('is_active') IS NULL ) AND ( is_featured = sqlc.narg('is_featured') + OR default_is_featured = sqlc.narg('is_featured') + OR sqlc.narg('is_featured') IS NULL + ) + AND ( + name ILIKE '%' || sqlc.narg('query') || '%' + OR sqlc.narg('query') IS NULL + ); +-- name: GetAllLeaguesWithSettings :many +SELECT l.*, + cls.company_id, + COALESCE(cls.is_active, l.default_is_active) AS is_active, + COALESCE(cls.is_featured, l.default_is_featured) AS is_featured, + cls.updated_at +FROM leagues l + LEFT JOIN company_league_settings cls ON l.id = cls.league_id + AND company_id = $1 +WHERE ( + country_code = sqlc.narg('country_code') + OR sqlc.narg('country_code') IS NULL + ) + AND ( + sport_id = sqlc.narg('sport_id') + OR sqlc.narg('sport_id') IS NULL + ) + AND ( + is_active = sqlc.narg('is_active') + OR default_is_active = sqlc.narg('is_active') + OR sqlc.narg('is_active') IS NULL + ) + AND ( + is_featured = sqlc.narg('is_featured') + OR default_is_featured = sqlc.narg('is_featured') OR sqlc.narg('is_featured') IS NULL ) AND ( diff --git a/gen/db/events.sql.go b/gen/db/events.sql.go index 3ee77ad..279cc8d 100644 --- a/gen/db/events.sql.go +++ b/gen/db/events.sql.go @@ -218,12 +218,19 @@ WHERE start_time > now() AND ( l.country_code = $7 OR $7 IS NULL - ) AND ( - ces.is_featured = $8 - OR $8 IS NULL -) + ) + AND ( + ces.is_featured = $8 + OR e.default_is_featured = $8 + OR $8 IS NULL + ) + AND ( + ces.is_active = $9 + OR e.default_is_active = $9 + OR $9 IS NULL + ) ORDER BY start_time ASC -LIMIT $10 OFFSET $9 +LIMIT $11 OFFSET $10 ` type GetEventsWithSettingsParams struct { @@ -235,6 +242,7 @@ type GetEventsWithSettingsParams struct { FirstStartTime pgtype.Timestamp `json:"first_start_time"` CountryCode pgtype.Text `json:"country_code"` IsFeatured pgtype.Bool `json:"is_featured"` + IsActive pgtype.Bool `json:"is_active"` Offset pgtype.Int4 `json:"offset"` Limit pgtype.Int4 `json:"limit"` } @@ -283,6 +291,7 @@ func (q *Queries) GetEventsWithSettings(ctx context.Context, arg GetEventsWithSe arg.FirstStartTime, arg.CountryCode, arg.IsFeatured, + arg.IsActive, arg.Offset, arg.Limit, ) @@ -531,8 +540,14 @@ WHERE is_live = false ) AND ( ces.is_featured = $8 + OR e.default_is_featured = $8 OR $8 IS NULL ) + AND ( + ces.is_active = $9 + OR e.default_is_active = $9 + OR $9 IS NULL + ) ` type GetTotalCompanyEventsParams struct { @@ -544,6 +559,7 @@ type GetTotalCompanyEventsParams struct { FirstStartTime pgtype.Timestamp `json:"first_start_time"` CountryCode pgtype.Text `json:"country_code"` IsFeatured pgtype.Bool `json:"is_featured"` + IsActive pgtype.Bool `json:"is_active"` } func (q *Queries) GetTotalCompanyEvents(ctx context.Context, arg GetTotalCompanyEventsParams) (int64, error) { @@ -556,6 +572,7 @@ func (q *Queries) GetTotalCompanyEvents(ctx context.Context, arg GetTotalCompany arg.FirstStartTime, arg.CountryCode, arg.IsFeatured, + arg.IsActive, ) var count int64 err := row.Scan(&count) diff --git a/gen/db/leagues.sql.go b/gen/db/leagues.sql.go index 57d3c28..1d2800b 100644 --- a/gen/db/leagues.sql.go +++ b/gen/db/leagues.sql.go @@ -102,7 +102,8 @@ SELECT l.id, l.name, l.img_url, l.country_code, l.bet365_id, l.sport_id, l.defau COALESCE(cls.is_featured, l.default_is_featured) AS is_featured, cls.updated_at FROM leagues l - LEFT JOIN company_league_settings cls ON l.id = cls.league_id AND company_id = $1 + LEFT JOIN company_league_settings cls ON l.id = cls.league_id + AND company_id = $1 WHERE ( country_code = $2 OR $2 IS NULL @@ -113,10 +114,12 @@ WHERE ( ) AND ( is_active = $4 + OR default_is_active = $4 OR $4 IS NULL ) AND ( is_featured = $5 + OR default_is_featured = $5 OR $5 IS NULL ) AND ( @@ -196,6 +199,58 @@ func (q *Queries) GetAllLeaguesWithSettings(ctx context.Context, arg GetAllLeagu return items, nil } +const GetTotalLeaguesWithSettings = `-- name: GetTotalLeaguesWithSettings :one +SELECT COUNT(*) +FROM leagues l + LEFT JOIN company_league_settings cls ON l.id = cls.league_id + AND company_id = $1 +WHERE ( + country_code = $2 + OR $2 IS NULL + ) + AND ( + sport_id = $3 + OR $3 IS NULL + ) + AND ( + is_active = $4 + OR default_is_active = $4 + OR $4 IS NULL + ) + AND ( + is_featured = $5 + OR default_is_featured = $5 + OR $5 IS NULL + ) + AND ( + name ILIKE '%' || $6 || '%' + OR $6 IS NULL + ) +` + +type GetTotalLeaguesWithSettingsParams struct { + CompanyID int64 `json:"company_id"` + CountryCode pgtype.Text `json:"country_code"` + SportID pgtype.Int4 `json:"sport_id"` + IsActive pgtype.Bool `json:"is_active"` + IsFeatured pgtype.Bool `json:"is_featured"` + Query pgtype.Text `json:"query"` +} + +func (q *Queries) GetTotalLeaguesWithSettings(ctx context.Context, arg GetTotalLeaguesWithSettingsParams) (int64, error) { + row := q.db.QueryRow(ctx, GetTotalLeaguesWithSettings, + arg.CompanyID, + arg.CountryCode, + arg.SportID, + arg.IsActive, + arg.IsFeatured, + arg.Query, + ) + var count int64 + err := row.Scan(&count) + return count, err +} + const InsertLeague = `-- name: InsertLeague :exec INSERT INTO leagues ( id, diff --git a/gen/db/models.go b/gen/db/models.go index 863dc14..ae21984 100644 --- a/gen/db/models.go +++ b/gen/db/models.go @@ -502,6 +502,14 @@ type RaffleTicket struct { IsActive pgtype.Bool `json:"is_active"` } +type RaffleWinner struct { + ID int32 `json:"id"` + RaffleID int32 `json:"raffle_id"` + UserID int32 `json:"user_id"` + Rank int32 `json:"rank"` + CreatedAt pgtype.Timestamp `json:"created_at"` +} + type ReferralCode struct { ID int64 `json:"id"` ReferralCode string `json:"referral_code"` @@ -514,14 +522,6 @@ type ReferralCode struct { UpdatedAt pgtype.Timestamptz `json:"updated_at"` } -type RaffleWinner struct { - ID int32 `json:"id"` - RaffleID int32 `json:"raffle_id"` - UserID int32 `json:"user_id"` - Rank int32 `json:"rank"` - CreatedAt pgtype.Timestamp `json:"created_at"` -} - type RefreshToken struct { ID int64 `json:"id"` UserID int64 `json:"user_id"` diff --git a/internal/domain/event.go b/internal/domain/event.go index 57a1d32..152f1de 100644 --- a/internal/domain/event.go +++ b/internal/domain/event.go @@ -219,6 +219,7 @@ type EventFilter struct { Offset ValidInt32 MatchStatus ValidString // e.g., "upcoming", "in_play", "ended" Featured ValidBool + Active ValidBool } func ConvertDBEvent(event dbgen.EventWithCountry) BaseEvent { diff --git a/internal/domain/league.go b/internal/domain/league.go index 0e0d65c..6743b6e 100644 --- a/internal/domain/league.go +++ b/internal/domain/league.go @@ -144,7 +144,7 @@ func ConvertDBBaseLeagues(leagues []dbgen.League) []BaseLeague { return result } -func ConvertDBLeagueWithSetting(lws dbgen.LeagueWithSetting) LeagueWithSettings { +func ConvertDBLeagueWithSetting(lws dbgen.GetAllLeaguesWithSettingsRow) LeagueWithSettings { return LeagueWithSettings{ ID: lws.ID, Name: lws.Name, @@ -167,7 +167,7 @@ func ConvertDBLeagueWithSetting(lws dbgen.LeagueWithSetting) LeagueWithSettings } } -func ConvertDBLeagueWithSettings(lws []dbgen.LeagueWithSetting) []LeagueWithSettings { +func ConvertDBLeagueWithSettings(lws []dbgen.GetAllLeaguesWithSettingsRow) []LeagueWithSettings { result := make([]LeagueWithSettings, len(lws)) for i, league := range lws { result[i] = ConvertDBLeagueWithSetting(league) diff --git a/internal/repository/event.go b/internal/repository/event.go index faf073e..9602796 100644 --- a/internal/repository/event.go +++ b/internal/repository/event.go @@ -86,6 +86,7 @@ func (s *Store) GetEventsWithSettings(ctx context.Context, companyID int64, filt LastStartTime: filter.LastStartTime.ToPG(), CountryCode: filter.CountryCode.ToPG(), IsFeatured: filter.Featured.ToPG(), + IsActive: filter.Active.ToPG(), }) if err != nil { @@ -101,6 +102,7 @@ func (s *Store) GetEventsWithSettings(ctx context.Context, companyID int64, filt LastStartTime: filter.LastStartTime.ToPG(), CountryCode: filter.CountryCode.ToPG(), IsFeatured: filter.Featured.ToPG(), + IsActive: filter.Active.ToPG(), }) if err != nil { return nil, 0, err diff --git a/internal/repository/league.go b/internal/repository/league.go index 4000b00..ae0a4d5 100644 --- a/internal/repository/league.go +++ b/internal/repository/league.go @@ -37,7 +37,8 @@ func (s *Store) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ( return domain.ConvertDBBaseLeagues(l), nil } -func (s *Store) GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, error) { +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, @@ -52,38 +53,26 @@ func (s *Store) GetAllLeaguesByCompany(ctx context.Context, companyID int64, fil Valid: filter.Offset.Valid, }, IsFeatured: filter.IsFeatured.ToPG(), - IsActive: filter.IsActive.ToPG(), + IsActive: filter.IsActive.ToPG(), }) if err != nil { - return nil, err + return nil, 0, 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, + 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(), + }) - DefaultIsActive: league.DefaultIsActive, - DefaultIsFeatured: league.DefaultIsFeatured, - } + if err != nil { + return nil, 0, err } - - return result, nil + return domain.ConvertDBLeagueWithSettings(l), total, nil } func (s *Store) CheckLeagueSupport(ctx context.Context, leagueID int64, companyID int64) (bool, error) { diff --git a/internal/services/league/port.go b/internal/services/league/port.go index b203c4f..54dc626 100644 --- a/internal/services/league/port.go +++ b/internal/services/league/port.go @@ -10,7 +10,7 @@ type Service interface { SaveLeague(ctx context.Context, league domain.CreateLeague) error SaveLeagueSettings(ctx context.Context, leagueSettings domain.CreateLeagueSettings) error GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague, error) - GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, error) + GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, int64, error) CheckLeagueSupport(ctx context.Context, leagueID int64, companyID int64) (bool, error) UpdateLeague(ctx context.Context, league domain.UpdateLeague) error } diff --git a/internal/services/league/service.go b/internal/services/league/service.go index d82b38f..9a3e1a3 100644 --- a/internal/services/league/service.go +++ b/internal/services/league/service.go @@ -29,7 +29,7 @@ func (s *service) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) return s.store.GetAllLeagues(ctx, filter) } -func (s *service) GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, error) { +func (s *service) GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, int64, error) { return s.store.GetAllLeaguesByCompany(ctx, companyID, filter) } diff --git a/internal/web_server/cron.go b/internal/web_server/cron.go index 1cf19c6..3c39dfc 100644 --- a/internal/web_server/cron.go +++ b/internal/web_server/cron.go @@ -26,71 +26,71 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S spec string task func() }{ - { - spec: "0 0 * * * *", // Every 1 hour - task: func() { - mongoLogger.Info("Began fetching upcoming events cron task") - if err := eventService.FetchUpcomingEvents(context.Background()); err != nil { - mongoLogger.Error("Failed to fetch upcoming events", - zap.Error(err), - ) - } else { - mongoLogger.Info("Completed fetching upcoming events without errors") - } - }, - }, - { - spec: "0 0 * * * *", // Every 1 hour (since its takes that long to fetch all the events) - task: func() { - mongoLogger.Info("Began fetching non live odds cron task") - if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil { - mongoLogger.Error("Failed to fetch non live odds", - zap.Error(err), - ) - } else { - mongoLogger.Info("Completed fetching non live odds without errors") - } - }, - }, - { - spec: "0 */5 * * * *", // Every 5 Minutes - task: func() { - mongoLogger.Info("Began update all expired events status cron task") - if _, err := resultService.CheckAndUpdateExpiredEvents(context.Background()); err != nil { - mongoLogger.Error("Failed to update expired events status", - zap.Error(err), - ) - } else { - mongoLogger.Info("Completed expired events without errors") - } - }, - }, - { - spec: "0 */15 * * * *", // Every 15 Minutes - task: func() { - mongoLogger.Info("Began fetching results for upcoming events cron task") - if err := resultService.FetchAndProcessResults(context.Background()); err != nil { - mongoLogger.Error("Failed to process result", - zap.Error(err), - ) - } else { - mongoLogger.Info("Completed processing all event result outcomes without errors") - } - }, - }, - { - spec: "0 0 0 * * *", // Every Day - task: func() { - mongoLogger.Info("Began Send daily result notification cron task") - if err := resultService.CheckAndSendResultNotifications(context.Background(), time.Now().Add(-24*time.Hour)); err != nil { - mongoLogger.Error("Failed to process result", - zap.Error(err), - ) - } else { - mongoLogger.Info("Completed sending daily result notification without errors") - } - }, - }, + // { + // spec: "0 0 * * * *", // Every 1 hour + // task: func() { + // mongoLogger.Info("Began fetching upcoming events cron task") + // if err := eventService.FetchUpcomingEvents(context.Background()); err != nil { + // mongoLogger.Error("Failed to fetch upcoming events", + // zap.Error(err), + // ) + // } else { + // mongoLogger.Info("Completed fetching upcoming events without errors") + // } + // }, + // }, + // { + // spec: "0 0 * * * *", // Every 1 hour (since its takes that long to fetch all the events) + // task: func() { + // mongoLogger.Info("Began fetching non live odds cron task") + // if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil { + // mongoLogger.Error("Failed to fetch non live odds", + // zap.Error(err), + // ) + // } else { + // mongoLogger.Info("Completed fetching non live odds without errors") + // } + // }, + // }, + // { + // spec: "0 */5 * * * *", // Every 5 Minutes + // task: func() { + // mongoLogger.Info("Began update all expired events status cron task") + // if _, err := resultService.CheckAndUpdateExpiredEvents(context.Background()); err != nil { + // mongoLogger.Error("Failed to update expired events status", + // zap.Error(err), + // ) + // } else { + // mongoLogger.Info("Completed expired events without errors") + // } + // }, + // }, + // { + // spec: "0 */15 * * * *", // Every 15 Minutes + // task: func() { + // mongoLogger.Info("Began fetching results for upcoming events cron task") + // if err := resultService.FetchAndProcessResults(context.Background()); err != nil { + // mongoLogger.Error("Failed to process result", + // zap.Error(err), + // ) + // } else { + // mongoLogger.Info("Completed processing all event result outcomes without errors") + // } + // }, + // }, + // { + // spec: "0 0 0 * * *", // Every Day + // task: func() { + // mongoLogger.Info("Began Send daily result notification cron task") + // if err := resultService.CheckAndSendResultNotifications(context.Background(), time.Now().Add(-24*time.Hour)); err != nil { + // mongoLogger.Error("Failed to process result", + // zap.Error(err), + // ) + // } else { + // mongoLogger.Info("Completed sending daily result notification without errors") + // } + // }, + // }, } for _, job := range schedule { diff --git a/internal/web_server/handlers/event_handler.go b/internal/web_server/handlers/event_handler.go index 2de000d..a149870 100644 --- a/internal/web_server/handlers/event_handler.go +++ b/internal/web_server/handlers/event_handler.go @@ -303,6 +303,7 @@ func (h *Handler) GetTenantUpcomingEvents(c *fiber.Ctx) error { Offset: offset, CountryCode: countryCode, Featured: isFeatured, + Active: domain.ValidBool{Value: true, Valid: true}, }) // fmt.Printf("League ID: %v", leagueID) @@ -347,12 +348,11 @@ func (h *Handler) GetTopLeagues(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, "invalid company id") } - leagues, err := h.leagueSvc.GetAllLeaguesByCompany(c.Context(), companyID.Value, domain.LeagueFilter{ + leagues, _, err := h.leagueSvc.GetAllLeaguesByCompany(c.Context(), companyID.Value, domain.LeagueFilter{ IsFeatured: domain.ValidBool{ Value: true, Valid: true, }, - }) if err != nil { @@ -371,6 +371,7 @@ func (h *Handler) GetTopLeagues(c *fiber.Ctx) error { Value: league.ID, Valid: true, }, + Active: domain.ValidBool{Value: true, Valid: true}, }) if err != nil { h.InternalServerErrorLogger().Warn("Error while fetching events for top league", @@ -570,7 +571,6 @@ type SetEventIsMonitoredReq struct { IsMonitored bool `json:"is_monitored"` } - // SetEventIsMonitored godoc // @Summary update the event is_monitored // @Description Update the event is_monitored diff --git a/internal/web_server/handlers/leagues.go b/internal/web_server/handlers/leagues.go index 4363e27..73abbf8 100644 --- a/internal/web_server/handlers/leagues.go +++ b/internal/web_server/handlers/leagues.go @@ -103,7 +103,7 @@ func (h *Handler) GetAllLeagues(c *fiber.Ctx) error { } res := domain.ConvertBaseLeagueResList(leagues) - + return response.WriteJSON(c, fiber.StatusOK, "All leagues retrieved", res, nil) } @@ -189,7 +189,7 @@ func (h *Handler) GetAllLeaguesForTenant(c *fiber.Ctx) error { zap.Bool("sport_id_valid", sportID.Valid), } - leagues, err := h.leagueSvc.GetAllLeaguesByCompany(c.Context(), companyID.Value, domain.LeagueFilter{ + leagues, total, err := h.leagueSvc.GetAllLeaguesByCompany(c.Context(), companyID.Value, domain.LeagueFilter{ CountryCode: countryCode, IsActive: isActive, SportID: sportID, @@ -206,7 +206,7 @@ func (h *Handler) GetAllLeaguesForTenant(c *fiber.Ctx) error { res := domain.ConvertLeagueWithSettingResList(leagues) - return response.WriteJSON(c, fiber.StatusOK, "All leagues retrieved", res, nil) + return response.WritePaginatedJSON(c, fiber.StatusOK, "All leagues retrieved", res, nil, page, int(total)) } type SetLeagueActiveReq struct {