Skip to content

Commit 8d50947

Browse files
committed
fix(backend): ensure total pages is at least 1
When there are no items, the total pages should be 1, not 0, as a page is still rendered.
1 parent cfc074d commit 8d50947

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

internal/backend/crud/interfaces.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ type PaginationMetadata struct {
3838
}
3939

4040
func CalculatePagination(total int64, limit, offset int) PaginationMetadata {
41-
totalPages := int((total + int64(limit) - 1) / int64(limit)) // Ceiling division
41+
totalPages := 1
42+
if total > 0 {
43+
totalPages = int((total + int64(limit) - 1) / int64(limit)) // Ceiling division
44+
}
4245
currentPage := (offset / limit) + 1
4346
hasNext := (offset + limit) < int(total)
4447
hasPrev := offset > 0

0 commit comments

Comments
 (0)