From 1e4b995034fccf6f03ebf015b6d9914ef149965b Mon Sep 17 00:00:00 2001 From: hippo-an Date: Tue, 5 Nov 2024 11:15:55 +0900 Subject: [PATCH] bug fix for estimate forecast cost group by then count query --- internal/core/cost/repository.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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)