Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e18b226356 | |||
|
a8a1c613a4
|
@@ -2,6 +2,12 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.0.4] - 2025-06-16
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- *(pagination)* Handle empty page return case
|
||||
|
||||
## [0.0.3] - 2025-06-16
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
@@ -88,6 +88,9 @@ func GetPage[T any](items []T, first *int, after *string, last *int, before *str
|
||||
eIx = idx
|
||||
}
|
||||
page := items[sIx:min(eIx, len(items))]
|
||||
if len(page) == 0 {
|
||||
return nil, PageInfo{}
|
||||
}
|
||||
return page, PageInfo{
|
||||
StartCursor: ptr(EncodeCursor(fn(page[0]))),
|
||||
HasNextPage: eIx < len(items),
|
||||
|
||||
@@ -45,6 +45,12 @@ func TestGetPage(t *testing.T) {
|
||||
EndCursor: ptr("Mg=="),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no more items",
|
||||
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(2), after: ptr("Mw=="), max: 10, fn: func(s string) string { return s }},
|
||||
wantItems: nil,
|
||||
wantPageInfo: PageInfo{},
|
||||
},
|
||||
{
|
||||
name: "first 10",
|
||||
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(10), max: 10, fn: func(s string) string { return s }},
|
||||
|
||||
Reference in New Issue
Block a user