fix pagination issues on backend

This commit is contained in:
Hayden 2022-12-31 11:43:55 -09:00
parent 188bd054e5
commit c379a73a63
No known key found for this signature in database
GPG key ID: 17CF79474E257545
2 changed files with 17 additions and 10 deletions

View file

@ -326,23 +326,23 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
)
}
count, err := qb.Count(ctx)
if err != nil {
return PaginationResult[ItemSummary]{}, err
}
qb = qb.Order(ent.Asc(item.FieldName)).
WithLabel().
WithLocation()
if q.Page != -1 || q.PageSize != -1 {
qb = qb.
Offset(calculateOffset(q.Page, q.PageSize)).
Limit(q.PageSize)
}
items, err := mapItemsSummaryErr(
qb.Order(ent.Asc(item.FieldName)).
WithLabel().
WithLocation().
All(ctx),
)
if err != nil {
return PaginationResult[ItemSummary]{}, err
}
items, err := mapItemsSummaryErr(qb.All(ctx))
count, err := qb.Count(ctx)
if err != nil {
return PaginationResult[ItemSummary]{}, err
}