Skip to content

Commit

Permalink
Set pagination max (#277)
Browse files Browse the repository at this point in the history
Sets a max for the pagination param across all endpoints of 500

Fixes #271
  • Loading branch information
kevinschaper authored Aug 15, 2023
1 parent ef43997 commit 733fc1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/src/monarch_py/api/additional_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class PaginationParams(BaseModel):
request: Request
limit: int = Query(default=20, ge=0)
limit: int = Query(default=20, ge=0, le=500)
offset: int = Query(default=0, ge=0)

class Config:
Expand Down
11 changes: 6 additions & 5 deletions backend/src/monarch_py/api/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import List, Union

from fastapi import APIRouter, Query # , Depends
from fastapi import APIRouter, Query, Depends

from monarch_py.api.additional_models import PaginationParams
from monarch_py.api.config import settings
from monarch_py.datamodels.model import SearchResults
from monarch_py.implementations.solr.solr_implementation import SolrImplementation
Expand All @@ -16,8 +18,7 @@ async def search(
q: str = "*:*",
category: Union[List[str], None] = Query(default=None),
in_taxon_label: Union[List[str], None] = Query(default=None),
offset: int = 0,
limit: int = 20,
pagination: PaginationParams = Depends(),
) -> SearchResults:
"""Search for entities by label, with optional filters
Expand All @@ -38,8 +39,8 @@ async def search(
category=category,
in_taxon_label=in_taxon_label,
facet_fields=facet_fields,
offset=offset,
limit=limit,
offset=pagination.offset,
limit=pagination.limit,
)

return response
Expand Down

0 comments on commit 733fc1a

Please sign in to comment.