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
it's more user-friendly.

Refs #3065
  • Loading branch information
melekes committed Jan 14, 2019
1 parent ec53ce3 commit 4d30658
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Special thanks to external contributors on this release:
### BREAKING CHANGES:

* CLI/RPC/Config
- [types] consistent field order of `CanonicalVote` and `CanonicalProposal`
- [types] consistent field order of `CanonicalVote` and `CanonicalProposal`

* Apps

Expand All @@ -21,5 +21,6 @@ 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:
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 4d30658

Please sign in to comment.