Spaces:
Sleeping
Sleeping
Update api/routes.py
Browse files- api/routes.py +11 -7
api/routes.py
CHANGED
|
@@ -165,21 +165,25 @@ async def count_patients(current_user: dict = Depends(get_current_user)):
|
|
| 165 |
print("π Authenticated user email:", email)
|
| 166 |
|
| 167 |
if not email or not isinstance(email, str):
|
| 168 |
-
|
|
|
|
| 169 |
|
| 170 |
if patients_collection is None:
|
| 171 |
-
print("β patients_collection is
|
| 172 |
-
raise HTTPException(status_code=500, detail="Database
|
| 173 |
|
| 174 |
-
filter_query = {"created_by": email}
|
| 175 |
-
print("π Running count_documents with:", filter_query)
|
| 176 |
|
| 177 |
count = await patients_collection.count_documents(filter_query)
|
| 178 |
|
| 179 |
-
print("β
|
| 180 |
return {"count": count}
|
| 181 |
|
| 182 |
except Exception as e:
|
|
|
|
|
|
|
| 183 |
print("β ERROR in /patients/count:", repr(e))
|
| 184 |
-
raise HTTPException(status_code=500, detail="Internal
|
|
|
|
| 185 |
|
|
|
|
| 165 |
print("π Authenticated user email:", email)
|
| 166 |
|
| 167 |
if not email or not isinstance(email, str):
|
| 168 |
+
print("β Email missing or invalid:", email)
|
| 169 |
+
raise HTTPException(status_code=400, detail="Invalid email in user context")
|
| 170 |
|
| 171 |
if patients_collection is None:
|
| 172 |
+
print("β patients_collection is None")
|
| 173 |
+
raise HTTPException(status_code=500, detail="Database connection issue")
|
| 174 |
|
| 175 |
+
filter_query = { "created_by": email }
|
| 176 |
+
print("π Running count_documents with filter:", filter_query)
|
| 177 |
|
| 178 |
count = await patients_collection.count_documents(filter_query)
|
| 179 |
|
| 180 |
+
print("β
Count result:", count)
|
| 181 |
return {"count": count}
|
| 182 |
|
| 183 |
except Exception as e:
|
| 184 |
+
import traceback
|
| 185 |
+
traceback.print_exc()
|
| 186 |
print("β ERROR in /patients/count:", repr(e))
|
| 187 |
+
raise HTTPException(status_code=500, detail="Internal Server Error")
|
| 188 |
+
|
| 189 |
|