Fix POI distance calculation for buy listings

The distance calculator always queried the rentlisting table regardless of
listing type because get_listings() defaulted to RentListing when called
without query_parameters. Added a listing_type parameter to get_listings()
and _get_model_for_query() so callers can select the correct table directly.
This commit is contained in:
Viktor Barzin 2026-02-08 19:10:32 +00:00
parent 54bdcac14a
commit e431eaf2aa
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 15 additions and 6 deletions

View file

@ -40,13 +40,14 @@ class ListingRepository:
query_parameters: QueryParameters | None = None,
only_ids: list[int] | None = None,
limit: int | None = None,
listing_type: ListingType | None = None,
) -> list[modelListing]:
"""
Get all listings from the database.
"""
only_ids = only_ids or []
model = self._get_model_for_query(query_parameters)
model = self._get_model_for_query(query_parameters, listing_type=listing_type)
query = select(model)
if only_ids:
@ -87,9 +88,18 @@ class ListingRepository:
yield listing
def _get_model_for_query(
self, query_parameters: QueryParameters | None
self,
query_parameters: QueryParameters | None,
listing_type: ListingType | None = None,
) -> type[RentListing] | type[BuyListing]:
"""Get the appropriate model class based on query parameters."""
"""Get the appropriate model class based on query parameters or explicit listing type.
The explicit listing_type parameter takes precedence over query_parameters.
"""
if listing_type == ListingType.BUY:
return BuyListing
if listing_type is not None:
return RentListing
if query_parameters and query_parameters.listing_type == ListingType.BUY:
return BuyListing
return RentListing