File tree Expand file tree Collapse file tree
src/ApiService/BookStore.ApiService Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public static RouteGroupBuilder MapBookEndpoints(this RouteGroupBuilder group)
2727 return group ;
2828 }
2929
30- static async Task < Ok < IPagedList < BookSearchProjection > > > SearchBooks (
30+ static async Task < Ok < PagedListDto < BookSearchProjection > > > SearchBooks (
3131 [ FromServices ] IQuerySession session ,
3232 [ AsParameters ] PagedRequest request ,
3333 [ FromQuery ] string ? q = null )
@@ -41,7 +41,7 @@ static async Task<Ok<IPagedList<BookSearchProjection>>> SearchBooks(
4141 . OrderBy ( b => b . Title )
4242 . ToPagedListAsync ( paging . Page ! . Value , paging . PageSize ! . Value ) ;
4343
44- return TypedResults . Ok ( pagedList ) ;
44+ return TypedResults . Ok ( PagedListDto < BookSearchProjection > . FromPagedList ( pagedList ) ) ;
4545 }
4646
4747 // Use NGram search for fuzzy, accent-insensitive matching
@@ -61,7 +61,7 @@ static async Task<Ok<IPagedList<BookSearchProjection>>> SearchBooks(
6161 // Use Marten's native pagination for optimal performance
6262 var searchResults = await query . ToPagedListAsync ( paging . Page ! . Value , paging . PageSize ! . Value ) ;
6363
64- return TypedResults . Ok ( searchResults ) ;
64+ return TypedResults . Ok ( PagedListDto < BookSearchProjection > . FromPagedList ( searchResults ) ) ;
6565 }
6666
6767 static async Task < IResult > GetBook (
Original file line number Diff line number Diff line change 1+ using Marten . Pagination ;
2+
3+ namespace BookStore . ApiService . Models ;
4+
5+ /// <summary>
6+ /// Represents a paginated list response for API clients
7+ /// </summary>
8+ public class PagedListDto < T >
9+ {
10+ public List < T > Items { get ; set ; } = [ ] ;
11+ public long PageNumber { get ; set ; }
12+ public long PageSize { get ; set ; }
13+ public long TotalItemCount { get ; set ; }
14+ public long PageCount { get ; set ; }
15+ public bool HasPreviousPage { get ; set ; }
16+ public bool HasNextPage { get ; set ; }
17+
18+ /// <summary>
19+ /// Creates a PagedListDto from Marten's IPagedList
20+ /// </summary>
21+ public static PagedListDto < T > FromPagedList ( IPagedList < T > pagedList )
22+ {
23+ return new PagedListDto < T >
24+ {
25+ Items = pagedList . ToList ( ) ,
26+ PageNumber = pagedList . PageNumber ,
27+ PageSize = pagedList . PageSize ,
28+ TotalItemCount = pagedList . TotalItemCount ,
29+ PageCount = pagedList . PageCount ,
30+ HasPreviousPage = pagedList . HasPreviousPage ,
31+ HasNextPage = pagedList . HasNextPage
32+ } ;
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments