Skip to content

Commit

Permalink
Merge pull request #51 from marcominerva/develop
Browse files Browse the repository at this point in the history
Add PaginatedListResult class
  • Loading branch information
marcominerva committed Feb 20, 2024
2 parents f63c7ec + 23b0536 commit 1dfef3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samples/MinimalApis/OperationResults.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
.Produces(StatusCodes.Status404NotFound)
.WithOpenApi();

app.Run();
app.Run();
40 changes: 40 additions & 0 deletions src/OperationResults/PaginatedListResult{ofT}.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace OperationResults;

public class PaginatedListResult<T>
{
public IEnumerable<T>? Items { get; set; }

public int PageIndex { get; set; }

public int PageSize { get; set; }

public int TotalCount { get; set; }

public bool HasNextPage { get; set; }

public PaginatedListResult()
{
}

public PaginatedListResult(IEnumerable<T>? items, int totalCount, int pageIndex, int pageSize = 0)
{
Items = items;
TotalCount = totalCount;
PageIndex = pageIndex;
PageSize = pageSize > 0 ? pageSize : items?.Count() ?? 0;
HasNextPage = totalCount > (pageIndex * PageSize) + (items?.Count() ?? 0);
}

public PaginatedListResult(IEnumerable<T>? items, bool hasNextPage = false) : this(items, items?.Count() ?? 0, hasNextPage)
{
}

public PaginatedListResult(IEnumerable<T>? items, int totalCount, bool hasNextPage = false)
{
Items = items;
TotalCount = totalCount;
PageIndex = 0;
PageSize = items?.Count() ?? 0;
HasNextPage = items?.Count() != totalCount && hasNextPage;
}
}

0 comments on commit 1dfef3f

Please sign in to comment.