diff --git a/internal/core/cost/repository.go b/internal/core/cost/repository.go index 57f934f..931ae88 100644 --- a/internal/core/cost/repository.go +++ b/internal/core/cost/repository.go @@ -262,6 +262,11 @@ func (r *CostRepository) GetEstimateForecastCostInfosTx(ctx context.Context, par Group("provider, resource_type, category, actual_resource_id, unit, date") } + + if err := d.Table("(?) AS sub", query).Count(&totalRows).Error; err != nil { + return err + } + if param.DateOrder != "" { query = query.Order("date " + string(param.DateOrder)) } @@ -270,10 +275,6 @@ func (r *CostRepository) GetEstimateForecastCostInfosTx(ctx context.Context, par query = query.Order("resource_type " + string(param.ResourceTypeOrder)) } - if err := query.Count(&totalRows).Error; err != nil { - return err - } - offset := (param.Page - 1) * param.Size query = query.Offset(offset). Limit(param.Size)