Spaces:
Sleeping
Sleeping
Update api/endpoints/location.py
Browse files- api/endpoints/location.py +15 -2
api/endpoints/location.py
CHANGED
|
@@ -8,7 +8,20 @@ router = APIRouter()
|
|
| 8 |
|
| 9 |
async def get_coordinates_v1(cord):
|
| 10 |
try:
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
except Exception as exc:
|
| 13 |
print(f'Coordinate {cord} generated an exception: {exc}')
|
| 14 |
return None
|
|
@@ -41,7 +54,7 @@ async def get_coordinates_route(user_id: str = Query(..., description="User's hu
|
|
| 41 |
|
| 42 |
|
| 43 |
@router.post("/get_card_reccomendation")
|
| 44 |
-
async def
|
| 45 |
token = data.jwt_token
|
| 46 |
user_id = sp.authenticate_user(token)
|
| 47 |
if user_id == "Exceptional error":
|
|
|
|
| 8 |
|
| 9 |
async def get_coordinates_v1(cord):
|
| 10 |
try:
|
| 11 |
+
# Assuming LocationService.get_coordinates is an async function
|
| 12 |
+
result = await LocationService.get_coordinates(cord)
|
| 13 |
+
|
| 14 |
+
# If the result is a coroutine, await it
|
| 15 |
+
if asyncio.iscoroutine(result):
|
| 16 |
+
result = await result
|
| 17 |
+
|
| 18 |
+
# Ensure the result is JSON serializable
|
| 19 |
+
json.dumps(result) # This will raise an error if result is not JSON serializable
|
| 20 |
+
|
| 21 |
+
return result
|
| 22 |
+
except json.JSONDecodeError:
|
| 23 |
+
print(f'Coordinate {cord} result is not JSON serializable')
|
| 24 |
+
return None
|
| 25 |
except Exception as exc:
|
| 26 |
print(f'Coordinate {cord} generated an exception: {exc}')
|
| 27 |
return None
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
@router.post("/get_card_reccomendation")
|
| 57 |
+
async def get_coordinates_v2(data: BodyData = Body(...)):
|
| 58 |
token = data.jwt_token
|
| 59 |
user_id = sp.authenticate_user(token)
|
| 60 |
if user_id == "Exceptional error":
|