return maxPerPage (not defaultPerPage) if per_page is greater than max (#3124)

it's more user-friendly.

Refs #3065
This commit is contained in:
Anton Kaliaev
2019-01-15 02:35:31 +04:00
committed by Ethan Buchman
parent bc00a032c1
commit 4daca1a634
3 changed files with 5 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ Special thanks to external contributors on this release:
### FEATURES:
### IMPROVEMENTS:
- [rpc] \#3065 return maxPerPage (100), not defaultPerPage (30) if `per_page` is greater than the max 100.
### BUG FIXES:
- [log] \#3060 fix year format

View File

@@ -149,8 +149,10 @@ func validatePage(page, perPage, totalCount int) int {
}
func validatePerPage(perPage int) int {
if perPage < 1 || perPage > maxPerPage {
if perPage < 1 {
return defaultPerPage
} else if perPage > maxPerPage {
return maxPerPage
}
return perPage
}

View File

@@ -47,7 +47,6 @@ func TestPaginationPage(t *testing.T) {
}
func TestPaginationPerPage(t *testing.T) {
cases := []struct {
totalCount int
perPage int
@@ -59,7 +58,7 @@ func TestPaginationPerPage(t *testing.T) {
{5, defaultPerPage, defaultPerPage},
{5, maxPerPage - 1, maxPerPage - 1},
{5, maxPerPage, maxPerPage},
{5, maxPerPage + 1, defaultPerPage},
{5, maxPerPage + 1, maxPerPage},
}
for _, c := range cases {