Ali2206 commited on
Commit
92b4a27
Β·
verified Β·
1 Parent(s): d93a5a1

Update api/routes.py

Browse files
Files changed (1) hide show
  1. api/routes.py +7 -9
api/routes.py CHANGED
@@ -18,7 +18,7 @@ async def signup(data: SignupForm):
18
  existing = await users_collection.find_one({"email": email})
19
  if existing:
20
  raise HTTPException(status_code=409, detail="Email already exists")
21
-
22
  hashed_pw = hash_password(data.password)
23
  user_doc = {
24
  "email": email,
@@ -62,7 +62,7 @@ async def add_patient(data: PatientCreate, current_user: dict = Depends(get_curr
62
  "created_at": datetime.utcnow()
63
  }
64
  result = await patients_collection.insert_one(patient_doc)
65
- return { "id": str(result.inserted_id), "message": "Patient created successfully" }
66
 
67
  # --- GET ALL PATIENTS ---
68
  @router.get("/patients")
@@ -156,7 +156,7 @@ async def delete_patient(patient_id: str, current_user: dict = Depends(get_curre
156
  raise HTTPException(status_code=404, detail="Patient not found or unauthorized")
157
 
158
  return {"message": "Patient deleted successfully"}
159
-
160
  # --- COUNT PATIENTS BY DOCTOR ---
161
  @router.get("/patients/count")
162
  async def count_patients(current_user: dict = Depends(get_current_user)):
@@ -166,14 +166,14 @@ async def count_patients(current_user: dict = Depends(get_current_user)):
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
 
@@ -185,5 +185,3 @@ async def count_patients(current_user: dict = Depends(get_current_user)):
185
  traceback.print_exc()
186
  print("❌ ERROR in /patients/count:", repr(e))
187
  raise HTTPException(status_code=500, detail="Internal Server Error")
188
-
189
-
 
18
  existing = await users_collection.find_one({"email": email})
19
  if existing:
20
  raise HTTPException(status_code=409, detail="Email already exists")
21
+
22
  hashed_pw = hash_password(data.password)
23
  user_doc = {
24
  "email": email,
 
62
  "created_at": datetime.utcnow()
63
  }
64
  result = await patients_collection.insert_one(patient_doc)
65
+ return {"id": str(result.inserted_id), "message": "Patient created successfully"}
66
 
67
  # --- GET ALL PATIENTS ---
68
  @router.get("/patients")
 
156
  raise HTTPException(status_code=404, detail="Patient not found or unauthorized")
157
 
158
  return {"message": "Patient deleted successfully"}
159
+
160
  # --- COUNT PATIENTS BY DOCTOR ---
161
  @router.get("/patients/count")
162
  async def count_patients(current_user: dict = Depends(get_current_user)):
 
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 user email")
170
 
171
  if patients_collection is None:
172
  print("❌ patients_collection is None")
173
+ raise HTTPException(status_code=500, detail="Database not connected")
174
 
175
+ filter_query = {"created_by": email}
176
+ print("πŸ” Running count_documents with:", filter_query)
177
 
178
  count = await patients_collection.count_documents(filter_query)
179
 
 
185
  traceback.print_exc()
186
  print("❌ ERROR in /patients/count:", repr(e))
187
  raise HTTPException(status_code=500, detail="Internal Server Error")