Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginated #18

Merged
merged 11 commits into from
Feb 20, 2024
Merged

Paginated #18

merged 11 commits into from
Feb 20, 2024

Conversation

igorbenav
Copy link
Owner

Paginated Summary

Added

  • Automatic get_paginated endpoint
  • Module paginated to handle utility functions
  • Docs updated to reflect it

Detailed


get_paginated endpoint

  • Endpoint: /get_paginated

  • Method: GET

  • Description: Retrieves multiple items with pagination.

  • Query Parameters:

    • page: The page number, starting from 1.
    • itemsPerPage: The number of items per page.
  • Example Request: GET /yourmodel/get_paginated?page=1&itemsPerPage=3.

  • Example Return:

{
  "data": [
    {"id": 1, "name": "Item 1", "description": "Description of item 1"},
    {"id": 2, "name": "Item 2", "description": "Description of item 2"},
    {"id": 3, "name": "Item 3", "description": "Description of item 3"}
  ],
  "total_count": 50,
  "has_more": true,
  "page": 1,
  "items_per_page": 10
}

paginated module

Functions:

  • 1. paginated_response:
paginated_response(
    crud_data: dict, page: int, items_per_page: int
) -> dict[str, Any]

Usage and Return example:

crud = FastCRUD(MyModel)
paginated_response(crud_data=crud.get_multi(MyModel), page=1, items_per_page=3)

returns

{
  "data": [
    {"id": 1, "name": "Item 1", "description": "Description of item 1"},
    {"id": 2, "name": "Item 2", "description": "Description of item 2"},
    {"id": 3, "name": "Item 3", "description": "Description of item 3"}
  ],
  "total_count": 50,
  "has_more": true,
  "page": 1,
  "items_per_page": 10
}
  • 2. compute_offset:
compute_offset(page: int, items_per_page: int) -> int

Usage and Return example:

offset(3, 10)

returns

20

@igorbenav igorbenav added the enhancement New feature or request label Feb 20, 2024
@igorbenav igorbenav self-assigned this Feb 20, 2024
@igorbenav igorbenav merged commit 7c947c8 into main Feb 20, 2024
10 checks passed
@igorbenav igorbenav deleted the paginated branch February 20, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant