DrfLikePaginations 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DrfLikePaginations --version 0.1.0
NuGet\Install-Package DrfLikePaginations -Version 0.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DrfLikePaginations" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DrfLikePaginations --version 0.1.0
#r "nuget: DrfLikePaginations, 0.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Coverage Lines of Code

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:

  • tests: run all the tests, and generate tests-reports folder with coverage data.
  • lint: check if the project is valid given standard dotnet-format rules
  • formatter: format the project given standard dotnet-format rules
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2 533 6/28/2021
1.1.1 340 6/27/2021
1.1.0 341 6/27/2021
1.0.0 473 6/26/2021
0.3.0 432 6/18/2021
0.2.0 320 6/18/2021
0.1.0 341 6/8/2021