From 54ae0539b46891e267175996bebec5fd12c0dbb2 Mon Sep 17 00:00:00 2001 From: Ernesto Ruge Date: Fri, 27 Oct 2023 13:48:17 +0200 Subject: [PATCH] fix postgis version issue --- webapp/models/parking_site.py | 6 ++++-- webapp/repositories/parking_site_repository.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/webapp/models/parking_site.py b/webapp/models/parking_site.py index f4e6c9b..4aa1549 100644 --- a/webapp/models/parking_site.py +++ b/webapp/models/parking_site.py @@ -76,7 +76,7 @@ class ParkingSite(BaseModel): public_url: Mapped[Optional[str]] = mapped_column(String(4096), nullable=True) address: Mapped[Optional[str]] = mapped_column(String(512), nullable=True) description: Mapped[Optional[str]] = mapped_column(String(4096), nullable=True) - type: Mapped[ParkingSiteType] = mapped_column(SqlalchemyEnum(ParkingSiteType), nullable=True) + type: Mapped[Optional[ParkingSiteType]] = mapped_column(SqlalchemyEnum(ParkingSiteType), nullable=True) max_stay: Mapped[Optional[int]] = mapped_column(Integer(), nullable=True) has_lighting: Mapped[Optional[bool]] = mapped_column(Boolean(), nullable=True) @@ -143,7 +143,9 @@ def to_dict(self, fields: Optional[list[str]] = None, ignore: Optional[list[str] 'realtime_capacity_bus', ] - return super().to_dict(fields, ignore) + result = super().to_dict(fields, ignore) + + return {key: value for key, value in result.items() if value is not None} @hybrid_property def park_and_ride_type(self) -> Mapped[Optional[list[ParkAndRideType]]]: diff --git a/webapp/repositories/parking_site_repository.py b/webapp/repositories/parking_site_repository.py index 6fdb596..76e5f8f 100644 --- a/webapp/repositories/parking_site_repository.py +++ b/webapp/repositories/parking_site_repository.py @@ -63,11 +63,11 @@ def _filter_by_search_query(self, query: Query, search_query: Optional[BaseSearc if hasattr(search_query, 'location') and hasattr(search_query, 'radius') and search_query.location: query = query.filter( - func.ST_Distance_Sphere( + func.ST_DistanceSphere( ParkingSite.geometry, func.ST_GeomFromText(f'POINT({float(search_query.location[1])} {float(search_query.location[0])})'), ) - < search_query.radius * 10000 + < search_query.radius * 1000 ) return query