From 8021f1a2918c70159cd47f59d9b86b119742e0d6 Mon Sep 17 00:00:00 2001 From: albertkun Date: Tue, 21 May 2024 18:58:07 -0700 Subject: [PATCH] Refactor get_route_details function in crud.py to use JSON deserialization for geometries --- fastapi/app/crud.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastapi/app/crud.py b/fastapi/app/crud.py index 6c2a51d..5a4215f 100644 --- a/fastapi/app/crud.py +++ b/fastapi/app/crud.py @@ -182,6 +182,7 @@ async def get_route_details(db: AsyncSession, route_code: str, direction_id: int # Extract shape_ids from stop_times shape_ids = {shape_id for stop in stop_times for shape_id in stop[1]['shape_ids']} + query = text("SELECT shape_id, ST_AsGeoJSON(geometry) FROM metro_api.trip_shapes WHERE shape_id IN :shape_ids") result = db.execute(query, {'shape_ids': tuple(shape_ids)}) @@ -189,7 +190,7 @@ async def get_route_details(db: AsyncSession, route_code: str, direction_id: int geometries_result = result.fetchall() # Process the geometries - geometries = {shape_id: geometry for shape_id, geometry in geometries_result} + geometries = {shape_id: json.loads(geometry) for shape_id, geometry in geometries_result} # Prepare the debugging information debug_info = {