Merge pull request 'feat: add limit/pagination to cardpositions endpoint (#142)' (#168) from issue/142-feat-add-limit-pagination-to-cardpositions-endpoin into main
This commit is contained in:
commit
792c6b96f9
@ -51,6 +51,7 @@ async def get_card_positions(
|
|||||||
cardset_id: list = Query(default=None),
|
cardset_id: list = Query(default=None),
|
||||||
short_output: Optional[bool] = False,
|
short_output: Optional[bool] = False,
|
||||||
sort: Optional[str] = "innings-desc",
|
sort: Optional[str] = "innings-desc",
|
||||||
|
limit: int = 100,
|
||||||
):
|
):
|
||||||
all_pos = (
|
all_pos = (
|
||||||
CardPosition.select()
|
CardPosition.select()
|
||||||
@ -86,6 +87,9 @@ async def get_card_positions(
|
|||||||
elif sort == "range-asc":
|
elif sort == "range-asc":
|
||||||
all_pos = all_pos.order_by(CardPosition.range, CardPosition.id)
|
all_pos = all_pos.order_by(CardPosition.range, CardPosition.id)
|
||||||
|
|
||||||
|
limit = max(0, min(limit, 500))
|
||||||
|
all_pos = all_pos.limit(limit)
|
||||||
|
|
||||||
return_val = {
|
return_val = {
|
||||||
"count": all_pos.count(),
|
"count": all_pos.count(),
|
||||||
"positions": [model_to_dict(x, recurse=not short_output) for x in all_pos],
|
"positions": [model_to_dict(x, recurse=not short_output) for x in all_pos],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user