Browse Source

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

it's more user-friendly.

Refs #3065
pull/3123/head
Anton Kaliaev 6 years ago
committed by Ethan Buchman
parent
commit
4daca1a634
3 changed files with 5 additions and 3 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +3
    -1
      rpc/core/pipe.go
  3. +1
    -2
      rpc/core/pipe_test.go

+ 1
- 0
CHANGELOG_PENDING.md 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

+ 3
- 1
rpc/core/pipe.go 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
}


+ 1
- 2
rpc/core/pipe_test.go 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 {


Loading…
Cancel
Save