2023-11-08 18:30:30 +01:00
|
|
|
package pagination
|
|
|
|
|
|
|
|
type Pagination struct {
|
2023-12-16 17:57:42 +01:00
|
|
|
Page int `json:"page"` // page (first page == 1)
|
|
|
|
Limit int `json:"limit"` // max-page-size
|
|
|
|
TotalPages int `json:"totalPages"` // total page-count
|
|
|
|
TotalItems int `json:"totalItems"` // total items-count
|
|
|
|
CurrentPageCount int `json:"currentPageCount"` // item-count in current page ( == len(data) )
|
2023-11-08 18:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func CalcPaginationTotalPages(totalItems int, limit int) int {
|
|
|
|
if totalItems == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
2024-01-06 01:31:07 +01:00
|
|
|
if limit == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
2023-11-08 18:30:30 +01:00
|
|
|
return 1 + (totalItems-1)/limit
|
|
|
|
}
|