Skip to content

Commit

Permalink
fix: fix missing total count when offset > 0 in list resources and li…
Browse files Browse the repository at this point in the history
…st approvals (#131)
  • Loading branch information
rahmatrhd authored Mar 15, 2024
1 parent 6ea2731 commit 407b192
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion internal/store/postgres/approval_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func (r *ApprovalRepository) ListApprovals(ctx context.Context, filter *domain.L

func (r *ApprovalRepository) GetApprovalsTotalCount(ctx context.Context, filter *domain.ListApprovalsFilter) (int64, error) {
db := r.db.WithContext(ctx)
db = applyFilter(db, filter)
f := filter
f.Size = 0
f.Offset = 0
db = applyFilter(db, f)

var count int64
if err := db.Model(&model.Approval{}).Count(&count).Error; err != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/store/postgres/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func (r *ResourceRepository) Find(ctx context.Context, filter domain.ListResourc

func (r *ResourceRepository) GetResourcesTotalCount(ctx context.Context, filter domain.ListResourcesFilter) (int64, error) {
db := r.db.WithContext(ctx)
db = applyResourceFilter(db, filter)

f := filter
f.Size = 0
f.Offset = 0
db = applyResourceFilter(db, f)
var count int64
err := db.Model(&model.Resource{}).Count(&count).Error

Expand Down

0 comments on commit 407b192

Please sign in to comment.