Merge branch 'feat/total-count' into 'main'

feat: add TotalCount field to PageInfo

See merge request unboundsoftware/pagination!64
This commit was merged in pull request #65.
This commit is contained in:
2026-01-01 21:37:46 +01:00
2 changed files with 10 additions and 0 deletions
+2
View File
@@ -109,6 +109,7 @@ func GetPage[T any](items []T, first *int, after *string, last *int, before *str
HasNextPage: eIx < len(items),
HasPreviousPage: sIx > 0,
EndCursor: ptr(EncodeCursor(fn(page[len(page)-1]))),
TotalCount: len(items),
}
}
@@ -121,4 +122,5 @@ type PageInfo struct {
HasNextPage bool
HasPreviousPage bool
EndCursor *string
TotalCount int
}
+8
View File
@@ -43,6 +43,7 @@ func TestGetPage(t *testing.T) {
StartCursor: ptr("MQ=="),
HasNextPage: true,
EndCursor: ptr("Mg=="),
TotalCount: 3,
},
},
{
@@ -59,6 +60,7 @@ func TestGetPage(t *testing.T) {
StartCursor: ptr("MQ=="),
HasNextPage: false,
EndCursor: ptr("Mw=="),
TotalCount: 3,
},
},
{
@@ -70,6 +72,7 @@ func TestGetPage(t *testing.T) {
HasNextPage: false,
HasPreviousPage: true,
EndCursor: ptr("NA=="),
TotalCount: 4,
},
},
{
@@ -81,6 +84,7 @@ func TestGetPage(t *testing.T) {
HasNextPage: false,
HasPreviousPage: true,
EndCursor: ptr("Mw=="),
TotalCount: 3,
},
},
{
@@ -92,6 +96,7 @@ func TestGetPage(t *testing.T) {
HasNextPage: false,
HasPreviousPage: true,
EndCursor: ptr("Mw=="),
TotalCount: 3,
},
},
{
@@ -103,6 +108,7 @@ func TestGetPage(t *testing.T) {
HasNextPage: true,
HasPreviousPage: false,
EndCursor: ptr("Mg=="),
TotalCount: 3,
},
},
{
@@ -114,6 +120,7 @@ func TestGetPage(t *testing.T) {
HasNextPage: true,
HasPreviousPage: false,
EndCursor: ptr("MQ=="),
TotalCount: 3,
},
},
{
@@ -125,6 +132,7 @@ func TestGetPage(t *testing.T) {
HasNextPage: false,
HasPreviousPage: false,
EndCursor: ptr("Mw=="),
TotalCount: 3,
},
},
}