Omkar008 commited on
Commit
b71f5c4
·
verified ·
1 Parent(s): a9ab215

Update api/endpoints/location.py

Browse files
Files changed (1) hide show
  1. 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
- return await LocationService.get_coordinates(cord)
 
 
 
 
 
 
 
 
 
 
 
 
 
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 get_coordinates(data: BodyData = Body(...)):
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":