Skip to content

Commit

Permalink
api: return empty list when page is empty (#2604)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Oct 30, 2023
1 parent 4b4d57f commit 8ed56fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func paginate2(itemsPtr interface{}, itemsPerPage int, page int) int {
}

min := page * itemsPerPage
if min >= itemsLen {
min = itemsLen - 1
if min > itemsLen {
min = itemsLen
}

max := (page + 1) * itemsPerPage
if max >= itemsLen {
if max > itemsLen {
max = itemsLen
}

Expand Down
6 changes: 3 additions & 3 deletions internal/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ func TestPagination(t *testing.T) {
pageCount, err = paginate(&items, "3", "2")
require.NoError(t, err)
require.Equal(t, 2, pageCount)
require.Equal(t, []int{4}, items)
require.Equal(t, []int{}, items)

items = make([]int, 6)
for i := 0; i < 6; i++ {
items[i] = i
}

pageCount, err = paginate(&items, "3", "3")
pageCount, err = paginate(&items, "4", "1")
require.NoError(t, err)
require.Equal(t, 2, pageCount)
require.Equal(t, []int{5}, items)
require.Equal(t, []int{4, 5}, items)
}

func TestAPIConfigGlobalGet(t *testing.T) {
Expand Down

0 comments on commit 8ed56fa

Please sign in to comment.