-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: add limit and offset parameters to routes that fetch lists from db #277
Open
blenzi
wants to merge
2
commits into
main
Choose a base branch
from
fetch-pagination
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -3,9 +3,10 @@ | ||
# This program is licensed under the Apache License 2.0. | # This program is licensed under the Apache License 2.0. | ||
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details. | # See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details. | ||
|
|
||
from typing import List | from typing import List, Optional | ||
|
|
||
from fastapi import APIRouter, Path, Security | from fastapi import APIRouter, Path, Query, Security | ||
from typing_extensions import Annotated | |||
|
|
||
from app.api import crud | from app.api import crud | ||
from app.api.deps import get_current_access | from app.api.deps import get_current_access | ||
|
@@ -25,8 +26,12 @@ async def get_access(access_id: int = Path(..., gt=0), _=Security(get_current_ac | ||
|
|
||
|
|
||
@router.get("/", response_model=List[AccessRead], summary="Get the list of all accesses") | @router.get("/", response_model=List[AccessRead], summary="Get the list of all accesses") | ||
async def fetch_accesses(_=Security(get_current_access, scopes=[AccessType.admin])): | async def fetch_accesses( | ||
limit: Annotated[int, Query(description="maximum number of items", ge=1, le=1000)] = 50, | |||
offset: Annotated[Optional[int], Query(description="number of items to skip", ge=0)] = None, | |||
_=Security(get_current_access, scopes=[AccessType.admin]), | |||
): | |||
Comment on lines
-28
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a reminder for me: how do we change those values when sending a request? |
|||
""" | """ | ||
Retrieves the list of all accesses and their information | Retrieves the list of all accesses and their information | ||
""" | """ | ||
return await crud.fetch_all(accesses) | return await crud.fetch_all(accesses, limit=limit, offset=offset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Two questions though:
.select()
?If we only want to paginate the queries, there are a few plugin options for this I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(paginate will prevent the case where we have a huge table and someone send
limit=100000
which might blow up the RAM)