Skip to content

Commit 4ccece1

Browse files
committed
bugfix(pagination): adjust pagination calculation and response structure
- fix hasNext calculation in endpoints manager
1 parent ab3518a commit 4ccece1

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

internal/collections/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ type CollectionsManager struct {
4444
type PaginatedCollections struct {
4545
Collections []CollectionEntity `json:"collections"`
4646
Total int64 `json:"total"`
47-
Offset int `json:"offset"`
48-
Limit int `json:"limit"`
4947
HasNext bool `json:"has_next"`
5048
HasPrev bool `json:"has_prev"`
49+
Limit int `json:"limit"`
50+
Offset int `json:"offset"`
5151
TotalPages int `json:"total_pages"`
5252
CurrentPage int `json:"current_page"`
5353
}

internal/endpoints/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ func (e *EndpointsManager) ListByCollection(ctx context.Context, collectionID in
9696
// Calculate pagination metadata
9797
totalPages := int((total + int64(limit) - 1) / int64(limit)) // Ceiling division
9898
currentPage := (offset / limit) + 1
99-
hasNext := offset+len(endpoints) < int(total)
99+
hasNext := (offset + limit) < int(total)
100100
hasPrev := offset > 0
101101

102102
result := &PaginatedEndpoints{
103103
Endpoints: entities,
104104
Total: total,
105-
Offset: int(offset),
106-
Limit: int(limit),
105+
Offset: offset,
106+
Limit: limit,
107107
HasNext: hasNext,
108108
HasPrev: hasPrev,
109109
TotalPages: totalPages,

internal/history/models.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ func (h HistoryEntity) GetUpdatedAt() time.Time {
3939
}
4040

4141
type PaginatedHistory struct {
42-
Items []HistoryEntity
43-
Total int64
44-
HasNext bool
45-
HasPrev bool
46-
Limit int
47-
Offset int
48-
TotalPages int
49-
CurrentPage int
42+
Items []HistoryEntity `json:"items"`
43+
Total int64 `json:"total"`
44+
HasNext bool `json:"has_next"`
45+
HasPrev bool `json:"has_prev"`
46+
Limit int `json:"limit"`
47+
Offset int `json:"offset"`
48+
TotalPages int `json:"total_pages"`
49+
CurrentPage int `json:"current_page"`
5050
}
5151

5252
type ExecutionData struct {

0 commit comments

Comments
 (0)