Add pagination support to the API #211
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket
Resolves #210
Changes
This adds pagination support to the API schema and DB queries
Added a new
POST /users/searchendpoint to have an example of a paginated endpoint.Context for reviewers
There are likely more features that could be built ontop of this (multi-field sorting, Paginator class as an iterator, and a few other utilities), but was focused on getting the core functionality of pagination working in a fairly general manner.
This approach for pagination is based on a mix of past projects and partially based on the Flask-SQLAlchemy libraries approach.
Testing
Added a bunch of users locally by calling the POST /users endpoint, but only one which would be found by the following query:
{ "is_active": true, "paging": { "page_offset": 1, "page_size": 25 }, "phone_number": "123-456-7890", "role_type": "USER", "sorting": { "order_by": "id", "sort_direction": "ascending" } }And got the following response (with the data removed as it's a lot):
{ "data": [...], "errors": [], "message": "Success", "pagination_info": { "order_by": "id", "page_offset": 1, "page_size": 25, "sort_direction": "ascending", "total_pages": 2, "total_records": 41 }, "status_code": 200, "warnings": [] }Further testing was done, and can be seen in the unit tests to verify the paging/sorting behavior.