Skip to content

Commit

Permalink
api: fix pagination if totalItems==0
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Jul 25, 2024
1 parent f70ff0a commit bbd1987
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ func parsePaginationParams(paramPage, paramLimit string) (PaginationParams, erro
func calculatePagination(page int, limit int, totalItems uint64) (*Pagination, error) {
// pages start at 0 index, for legacy reasons
lastp := int(math.Ceil(float64(totalItems)/float64(limit)) - 1)
if totalItems == 0 {
lastp = 0
}

if page > lastp || page < 0 {
return nil, ErrPageNotFound
Expand Down

0 comments on commit bbd1987

Please sign in to comment.