Skip to content

Commit

Permalink
return maxPerPage (not defaultPerPage) if per_page is greater than max (
Browse files Browse the repository at this point in the history
#3124)

it's more user-friendly.

Refs #3065
  • Loading branch information
melekes authored and ebuchman committed Jan 14, 2019
1 parent bc00a03 commit 4daca1a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion rpc/core/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions rpc/core/pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestPaginationPage(t *testing.T) {
}

func TestPaginationPerPage(t *testing.T) {

cases := []struct {
totalCount int
perPage int
Expand All @@ -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 {
Expand Down

0 comments on commit 4daca1a

Please sign in to comment.