This commit is contained in:
parent
13774eec7d
commit
45fcecdc04
29 changed files with 2865 additions and 3867 deletions
18
internal/service/pagination.go
Normal file
18
internal/service/pagination.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package service
|
||||
|
||||
// Paginate calculates pagination values from a page number, total count, and page size.
|
||||
// Returns the adjusted page, total pages, and offset for the query.
|
||||
func Paginate(page, total, perPage int) (adjustedPage, totalPages, offset int) {
|
||||
totalPages = (total + perPage - 1) / perPage
|
||||
if totalPages < 1 {
|
||||
totalPages = 1
|
||||
}
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if page > totalPages {
|
||||
page = totalPages
|
||||
}
|
||||
offset = (page - 1) * perPage
|
||||
return page, totalPages, offset
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue