DrfLikePaginations 0.1.0
See the version list below for details.
dotnet add package DrfLikePaginations --version 0.1.0
NuGet\Install-Package DrfLikePaginations -Version 0.1.0
<PackageReference Include="DrfLikePaginations" Version="0.1.0" />
paket add DrfLikePaginations --version 0.1.0
#r "nuget: DrfLikePaginations, 0.1.0"
// Install DrfLikePaginations as a Cake Addin #addin nuget:?package=DrfLikePaginations&version=0.1.0 // Install DrfLikePaginations as a Cake Tool #tool nuget:?package=DrfLikePaginations&version=0.1.0
DRF Like Paginations
This project is an attempt to mimic LimitOffsetPagination that is available on DRF. Many other types of paginations can be incorporated beyond the ones available here. This is just a start.
dotnet add package DrfLikePaginations
Sample output
You can check out one sample output below from the project ef-core-how-to-handle-migrations-in-production:
{
"count": 100,
"next": "http://0.0.0.0:8000/api/v1/todoitems?limit=5&offset=5",
"previous": null,
"results": [
{
"name": "TD 1",
"isComplete": false,
"id": 1,
"createdAt": "2021-06-08T19:00:17.873423",
"updatedAt": "2021-06-08T19:00:17.87347"
},
{
"name": "TD 73",
"isComplete": false,
"id": 2,
"createdAt": "2021-06-08T19:00:17.873571",
"updatedAt": "2021-06-08T19:00:17.873571"
},
{
"name": "TD 72",
"isComplete": true,
"id": 3,
"createdAt": "2021-06-08T19:00:17.87357",
"updatedAt": "2021-06-08T19:00:17.87357"
},
{
"name": "TD 71",
"isComplete": false,
"id": 4,
"createdAt": "2021-06-08T19:00:17.87357",
"updatedAt": "2021-06-08T19:00:17.87357"
},
{
"name": "TD 70",
"isComplete": true,
"id": 5,
"createdAt": "2021-06-08T19:00:17.873569",
"updatedAt": "2021-06-08T19:00:17.873569"
}
]
}
How to use it
You can add the following in your appsettings.json
:
{
"Pagination": {
"Size": 5
}
}
Then configure the pagination service like the following:
var paginationSize = int.Parse(Configuration["Pagination:Size"]);
services.AddSingleton<IPagination>(new Pagination(paginationSize));
Now you are able to use it 😍! One full example:
namespace EFCoreHandlingMigrations.Controllers.V1
{
[ApiController]
[Route("api/v1/[controller]")]
public class TodoItemsController : ControllerBase
{
private readonly DbSet<TodoItem> _databaseSet;
private readonly IPagination _pagination;
public TodoItemsController(AppDbContext context, IPagination pagination)
{
_databaseSet = context.TodoItems;
_pagination = pagination;
}
[HttpGet]
public async Task<Paginated<TodoItem>> GetTodoItems()
{
var query = _databaseSet.AsQueryable();
var displayUrl = Request.GetDisplayUrl();
var queryParams = Request.Query;
return await _pagination.CreateAsync(query, displayUrl, queryParams);
}
}
}
Compose services
If you look at docker-compose.yaml, you'll find three main services:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.EntityFrameworkCore (>= 5.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.