@@ -104,7 +104,7 @@ func (c *CollectionsManager) List(ctx context.Context) ([]CollectionEntity, erro
104104 return paginated .Collections , nil
105105}
106106
107- func (c * CollectionsManager ) ListPaginated (ctx context.Context , limit , offset int64 ) (* PaginatedCollections , error ) {
107+ func (c * CollectionsManager ) ListPaginated (ctx context.Context , limit , offset int ) (* PaginatedCollections , error ) {
108108 log .Debug ("listing paginated collections" , "limit" , limit , "offset" , offset )
109109
110110 total , err := c .DB .CountCollections (ctx )
@@ -114,8 +114,8 @@ func (c *CollectionsManager) ListPaginated(ctx context.Context, limit, offset in
114114 }
115115
116116 collections , err := c .DB .GetCollectionsPaginated (ctx , database.GetCollectionsPaginatedParams {
117- Limit : limit ,
118- Offset : offset ,
117+ Limit : int64 ( limit ) ,
118+ Offset : int64 ( offset ) ,
119119 })
120120 if err != nil {
121121 log .Error ("failed to get paginated collections" , "limit" , limit , "offset" , offset , "error" , err )
@@ -127,17 +127,12 @@ func (c *CollectionsManager) ListPaginated(ctx context.Context, limit, offset in
127127 entities [i ] = CollectionEntity {Collection : collection }
128128 }
129129
130- hasNext := offset + int64 (len (collections )) < total
131- hasPrev := offset > 0
130+ pagination := crud .CalculatePagination (total , limit , offset )
132131
133- log .Debug ("retrieved paginated collections" , "total" , total , "returned" , len (entities ), "has_next" , hasNext , "has_prev" , hasPrev )
134-
135- return & PaginatedCollections {
136- Collections : entities ,
137- Total : total ,
138- Offset : offset ,
139- Limit : limit ,
140- HasNext : hasNext ,
141- HasPrev : hasPrev ,
142- }, nil
132+ result := & PaginatedCollections {
133+ Collections : entities ,
134+ PaginationMetadata : pagination ,
135+ }
136+ log .Info ("retrieved collections" , "count" , len (entities ), "total" , pagination .Total , "page" , pagination .CurrentPage , "total_pages" , pagination .TotalPages )
137+ return result , nil
143138}
0 commit comments