35 lines
669 B
Go
35 lines
669 B
Go
package response
|
|
|
|
type PaginationHelper struct{}
|
|
|
|
func NewPaginationHelper() *PaginationHelper {
|
|
return &PaginationHelper{}
|
|
}
|
|
|
|
func (p *PaginationHelper) BuildPagingMeta(offset, limit int, total int64) *PagingMeta {
|
|
page := 1
|
|
if limit > 0 {
|
|
page = (offset / limit) + 1
|
|
}
|
|
|
|
return &PagingMeta{
|
|
Page: page,
|
|
Total: total,
|
|
Limit: limit,
|
|
}
|
|
}
|
|
|
|
func (p *PaginationHelper) calculateTotalPages(total int64, limit int) int {
|
|
if limit <= 0 {
|
|
return 1
|
|
}
|
|
return int((total + int64(limit) - 1) / int64(limit))
|
|
}
|
|
|
|
func (p *PaginationHelper) hasNextPage(offset, limit int, total int64) bool {
|
|
if limit <= 0 {
|
|
return false
|
|
}
|
|
return int64(offset+limit) < total
|
|
}
|