Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/api/endpoints/search/agency/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ def __init__(
location_id: int | None,
query: str | None,
jurisdiction_type: JurisdictionType | None,
page: int
):
super().__init__()
self.location_id = location_id
self.query = query
self.jurisdiction_type = jurisdiction_type
self.page = page

async def run(self, session: AsyncSession) -> list[AgencySearchResponse]:

Expand Down Expand Up @@ -68,7 +70,7 @@ async def run(self, session: AsyncSession) -> list[AgencySearchResponse]:
).desc()
)

query = query.limit(50)
query = query.limit(10).offset((self.page - 1) * 10)

mappings: Sequence[RowMapping] = await sh.mappings(session, query)

Expand Down
7 changes: 6 additions & 1 deletion src/api/endpoints/search/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ async def search_agency(
description="The jurisdiction type to search for",
default=None
),
page: int = Query(
description="The page to search for",
default=1
),
access_info: AccessInfo = Depends(get_access_info),
async_core: AsyncCore = Depends(get_async_core),
) -> list[AgencySearchResponse]:
Expand All @@ -53,6 +57,7 @@ async def search_agency(
SearchAgencyQueryBuilder(
location_id=location_id,
query=query,
jurisdiction_type=jurisdiction_type
jurisdiction_type=jurisdiction_type,
page=page
)
)
10 changes: 10 additions & 0 deletions tests/automated/integration/api/search/agency/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ async def test_search_agency(
}
)
assert len(responses) == 3

# Test pagination
responses = api_test_helper.request_validator.get_v2(
url="/search/agency",
params={
"query": "A Agency",
"location_id": allegheny_county.location_id,
"page": 2
}
)