Merge current v2.11 into v3.1

This commit is contained in:
romain 2024-08-28 16:11:38 +02:00
commit 85f4fd0979
40 changed files with 114 additions and 116 deletions

View file

@ -93,7 +93,7 @@ func (c *searchCriterion) filterMiddleware(mns []string) bool {
return false
}
func pagination(request *http.Request, max int) (pageInfo, error) {
func pagination(request *http.Request, maximum int) (pageInfo, error) {
perPage, err := getIntParam(request, "per_page", defaultPerPage)
if err != nil {
return pageInfo{}, err
@ -105,17 +105,17 @@ func pagination(request *http.Request, max int) (pageInfo, error) {
}
startIndex := (page - 1) * perPage
if startIndex != 0 && startIndex >= max {
if startIndex != 0 && startIndex >= maximum {
return pageInfo{}, fmt.Errorf("invalid request: page: %d, per_page: %d", page, perPage)
}
endIndex := startIndex + perPage
if endIndex >= max {
endIndex = max
if endIndex >= maximum {
endIndex = maximum
}
nextPage := 1
if page*perPage < max {
if page*perPage < maximum {
nextPage = page + 1
}