{"id":21354575,"url":"https://github.com/willianantunes/drf-like-paginations","last_synced_at":"2025-07-12T22:32:03.766Z","repository":{"id":49130443,"uuid":"374775171","full_name":"willianantunes/drf-like-paginations","owner":"willianantunes","description":"Tired of creating pagination all the time in your .NET projects? Apply either Offset or Cursor pagination and focus on business logic 🙂","archived":false,"fork":false,"pushed_at":"2021-06-28T20:46:08.000Z","size":11623,"stargazers_count":22,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-08T06:12:06.536Z","etag":null,"topics":["containerization","cursor-pagination","dotnet-core","entity-framework","pagination","sonarcloud","xunit"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/DrfLikePaginations/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willianantunes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-07T19:14:26.000Z","updated_at":"2024-09-02T12:12:56.000Z","dependencies_parsed_at":"2022-09-21T04:42:30.121Z","dependency_job_id":null,"html_url":"https://github.com/willianantunes/drf-like-paginations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willianantunes%2Fdrf-like-paginations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willianantunes%2Fdrf-like-paginations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willianantunes%2Fdrf-like-paginations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willianantunes%2Fdrf-like-paginations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willianantunes","download_url":"https://codeload.github.com/willianantunes/drf-like-paginations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225839615,"owners_count":17532307,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["containerization","cursor-pagination","dotnet-core","entity-framework","pagination","sonarcloud","xunit"],"created_at":"2024-11-22T04:13:43.129Z","updated_at":"2024-11-22T04:13:44.617Z","avatar_url":"https://github.com/willianantunes.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DRF Like Paginations\n\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=willianantunes_drf-like-paginations\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=willianantunes_drf-like-paginations)\n[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=willianantunes_drf-like-paginations\u0026metric=ncloc)](https://sonarcloud.io/dashboard?id=willianantunes_drf-like-paginations)\n\nThis project is an attempt to mimic [LimitOffsetPagination](https://www.django-rest-framework.org/api-guide/pagination/#limitoffsetpagination) and [CursorPagination](https://www.django-rest-framework.org/api-guide/pagination/#cursorpagination) that are available on DRF. Many other types of paginations can be incorporated beyond the ones available [here](https://www.django-rest-framework.org/api-guide/pagination/#api-reference). This is just a start.\n\n    dotnet add package DrfLikePaginations\n\nIt supports **queries in your data** given what is informed through the URL as query strings. You can get some details about how it works if you look at the tests in [LimitOffsetPaginationITests.Queries](https://github.com/willianantunes/drf-like-paginations/blob/6c4dc9ae2f00643514f3898d54ce085443788df3/tests/DrfLikePaginations/LimitOffsetPaginationITests.cs#L218) class.\n\nIt also support **model transformation**. If you don't want to expose your model, you can create a DTO and then provide a function which transforms your data. Check out one example on [this integration test](https://github.com/willianantunes/drf-like-paginations/blob/6c4dc9ae2f00643514f3898d54ce085443788df3/tests/DrfLikePaginations/LimitOffsetPaginationITests.cs#L353-L371).\n\nThe following project is using it and you can use as an example to set up yours:\n\n- [Tic Tac Toe C# Playground](https://github.com/willianantunes/tic-tac-toe-csharp-playground)\n\n## See it in action!\n\nSample GIF that shows `CursorPagination`:\n\n![Sample usage of how CursorPagination works](docs/drflp-cursor-sample.gif)\n\nSample GIF that shows `LimitOffsetPagination`:\n\n![Sample usage of how LimitOffsetPagination works](docs/drflp-offset-sample.gif)\n\n## How to use it\n\nYou can add the following in your `appsettings.json`:\n\n```json\n{\n  \"Pagination\": {\n    \"Size\": 5\n  }\n}\n```\n\nThen configure the pagination service like the following for `LimitOffsetPagination`:\n\n```csharp\nvar paginationSize = int.Parse(Configuration[\"Pagination:Size\"]);\nservices.AddSingleton\u003cIPagination\u003e(new LimitOffsetPagination(paginationSize));\n```\n\nYou can use `CursorPagination` also:\n\n```csharp\nvar paginationSize = int.Parse(Configuration[\"Pagination:Size\"]);\n// It will consider the field \"id\" to order by default, but you can change it 😄\nservices.AddSingleton\u003cIPagination\u003e(new CursorPagination(paginationSize));\n```\n\nNow you are able to use it 😍! One full example:\n\n```csharp\nnamespace EFCoreHandlingMigrations.Controllers.V1\n{\n    [ApiController]\n    [Route(\"api/v1/[controller]\")]\n    public class TodoItemsController : ControllerBase\n    {\n        private readonly DbSet\u003cTodoItem\u003e _databaseSet;\n        private readonly IPagination _pagination;\n\n        public TodoItemsController(AppDbContext context, IPagination pagination)\n        {\n            _databaseSet = context.TodoItems;\n            _pagination = pagination;\n        }\n\n        [HttpGet]\n        public async Task\u003cPaginated\u003cTodoItem\u003e\u003e GetTodoItems()\n        {\n            // You just need to apply OrderBy when using LimitOffsetPagination \n            var query = _databaseSet.AsNoTracking().OrderBy(t =\u003e t.CreatedAt);\n            var displayUrl = Request.GetDisplayUrl();\n            var queryParams = Request.Query;\n\n            return await _pagination.CreateAsync(query, displayUrl, queryParams);\n        }\n    }\n}\n```\n\n## Compose services\n\nIf you look at [docker-compose.yaml](https://github.com/willianantunes/drf-like-paginations/blob/abdce3ab9293af95d923cf0b25634f555fad4aaa/docker-compose.yaml#L7-L30), you'll find three main services:\n\n- [tests](https://github.com/willianantunes/drf-like-paginations/blob/fff46e8627c1bfd23fcc2ef7fe9e8663e6e87156/docker-compose.yaml#L7): run all the tests, and generate tests-reports folder with coverage data.\n- [lint](https://github.com/willianantunes/drf-like-paginations/blob/fff46e8627c1bfd23fcc2ef7fe9e8663e6e87156/docker-compose.yaml#L15): check if the project is valid given standard dotnet-format rules\n- [formatter](https://github.com/willianantunes/drf-like-paginations/blob/fff46e8627c1bfd23fcc2ef7fe9e8663e6e87156/docker-compose.yaml#L23): format the project given standard dotnet-format rules\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillianantunes%2Fdrf-like-paginations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillianantunes%2Fdrf-like-paginations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillianantunes%2Fdrf-like-paginations/lists"}