Fix tests to match decision service API and add filtering to non-streaming endpoint
- Update test mocks from _get_disliked_ids to _get_user_id_safe - Fix decision service test method names (clear_decision -> remove_decision, etc.) - Fix positional vs keyword arg assertion in set_decision test - Add decision_filter param to non-streaming listing_geojson endpoint
This commit is contained in:
parent
a2745c1478
commit
43f9d210fb
3 changed files with 26 additions and 7 deletions
19
api/app.py
19
api/app.py
|
|
@ -171,6 +171,7 @@ async def get_listing_geojson(
|
|||
user: Annotated[User, Depends(get_current_user)],
|
||||
query_parameters: Annotated[QueryParameters, Depends(get_query_parameters)],
|
||||
limit: int | None = None,
|
||||
decision_filter: str = "all",
|
||||
) -> dict:
|
||||
"""Get listings as GeoJSON for map display."""
|
||||
if limit is not None:
|
||||
|
|
@ -183,6 +184,24 @@ async def get_listing_geojson(
|
|||
query_parameters=query_parameters,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
# Apply decision filtering
|
||||
if decision_filter != "everything":
|
||||
user_id = _get_user_id_safe(user.email)
|
||||
if user_id is not None:
|
||||
decision_repo = DecisionRepository(engine)
|
||||
disliked_ids = decision_service.get_disliked_ids(decision_repo, user_id, query_parameters.listing_type.value) if decision_filter == "all" else None
|
||||
liked_ids = decision_service.get_liked_ids(decision_repo, user_id, query_parameters.listing_type.value) if decision_filter == "liked" else None
|
||||
features = result.data.get("features", [])
|
||||
features = [
|
||||
f for f in features
|
||||
if _should_include(
|
||||
f.get("properties", {}).get("id", 0),
|
||||
decision_filter, disliked_ids, liked_ids,
|
||||
)
|
||||
]
|
||||
result.data["features"] = features
|
||||
|
||||
return result.data
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue