Skip to content

Commit 60343cd

Browse files
committed
[DOP-22530] Allow multi value GET /v1/locations?location_type=...
1 parent c5f6a5a commit 60343cd

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

data_rentgen/db/repositories/location.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ async def paginate(
5151
page: int,
5252
page_size: int,
5353
location_ids: Collection[int],
54-
location_type: str | None,
54+
location_type: Collection[str],
5555
search_query: str | None,
5656
) -> PaginationDTO[Location]:
5757
where = []
58-
5958
if location_ids:
6059
where.append(Location.id == any_(list(location_ids))) # type: ignore[arg-type]
61-
6260
if location_type:
63-
where.append(Location.type == location_type)
61+
location_type_lower = [location_type.lower() for location_type in location_type]
62+
where.append(Location.type == any_(location_type_lower)) # type: ignore[arg-type]
6463

6564
query: Select | CompoundSelect
6665
order_by: list[ColumnElement | SQLColumnExpression]

data_rentgen/server/schemas/v1/location.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class LocationPaginateQueryV1(PaginateQueryV1):
6666
"""Query params for Location paginate request."""
6767

6868
location_id: list[int] = Field(default_factory=list, description="Location id")
69-
location_type: str | None = Field(
70-
default=None,
69+
location_type: list[str] = Field(
70+
default_factory=list,
7171
description="Location type",
72-
examples=["kafka", "hdfs", "yarn"],
72+
examples=[["kafka", "hdfs"], ["yarn"]],
7373
)
7474
search_query: str | None = Field(
7575
default=None,

data_rentgen/server/services/location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def paginate(
6262
page: int,
6363
page_size: int,
6464
location_ids: Collection[int],
65-
location_type: str | None,
65+
location_type: Collection[str],
6666
search_query: str | None,
6767
) -> LocationServicePaginatedResult:
6868
pagination = await self._uow.location.paginate(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow passing multiple ``location_type`` filters to ``GET /v1/locations``.

tests/test_server/test_locations/test_get_locations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def test_get_locations_with_type_filter(
8282
response = await test_client.get(
8383
"v1/locations",
8484
headers={"Authorization": f"Bearer {mocked_user.access_token}"},
85-
params={"location_type": location_type},
85+
params={"location_type": location_type.upper()}, # case-insensitive
8686
)
8787

8888
assert response.status_code == HTTPStatus.OK, response.json()

0 commit comments

Comments
 (0)