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:
parent
54bdcac14a
commit
e431eaf2aa
2 changed files with 15 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue