Update main.py
Browse files
main.py
CHANGED
|
@@ -626,6 +626,7 @@ def list_doctors_with_favorites(
|
|
| 626 |
order: str = "id.asc",
|
| 627 |
client_email: Optional[str] = None,
|
| 628 |
client_mobile: Optional[str] = None,
|
|
|
|
| 629 |
):
|
| 630 |
"""
|
| 631 |
يرجّع قائمة الدكاترة + is_favorite لكل دكتور بحسب مفضّلات العميل.
|
|
@@ -651,18 +652,29 @@ def list_doctors_with_favorites(
|
|
| 651 |
|
| 652 |
# 3) هات المفضّلات (doctor_id فقط)
|
| 653 |
fav_params = {"select": "doctor_id", "limit": "10000", "order": "created_at.desc"}
|
| 654 |
-
if client_email:
|
| 655 |
-
|
| 656 |
-
if client_mobile:
|
| 657 |
-
fav_params["client_mobile"] = f"eq.{client_mobile}"
|
| 658 |
|
| 659 |
favorites = supa_select("favorites", fav_params)
|
| 660 |
fav_ids = {row.get("doctor_id") for row in favorites if row.get("doctor_id") is not None}
|
| 661 |
|
| 662 |
-
# 4)
|
| 663 |
-
|
| 664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
|
|
|
|
| 666 |
|
| 667 |
@app.get("/api/doctors/{doctor_id}/details")
|
| 668 |
def doctor_details(doctor_id: int):
|
|
|
|
| 626 |
order: str = "id.asc",
|
| 627 |
client_email: Optional[str] = None,
|
| 628 |
client_mobile: Optional[str] = None,
|
| 629 |
+
only_favorites: bool = False, # اختياري: رجّع المفضلة فقط
|
| 630 |
):
|
| 631 |
"""
|
| 632 |
يرجّع قائمة الدكاترة + is_favorite لكل دكتور بحسب مفضّلات العميل.
|
|
|
|
| 652 |
|
| 653 |
# 3) هات المفضّلات (doctor_id فقط)
|
| 654 |
fav_params = {"select": "doctor_id", "limit": "10000", "order": "created_at.desc"}
|
| 655 |
+
if client_email: fav_params["client_email"] = f"eq.{client_email}"
|
| 656 |
+
if client_mobile: fav_params["client_mobile"] = f"eq.{client_mobile}"
|
|
|
|
|
|
|
| 657 |
|
| 658 |
favorites = supa_select("favorites", fav_params)
|
| 659 |
fav_ids = {row.get("doctor_id") for row in favorites if row.get("doctor_id") is not None}
|
| 660 |
|
| 661 |
+
# 4) شكّل الخرج بالشكل المطلوب + فلتر اختياري
|
| 662 |
+
shaped = []
|
| 663 |
+
for d in doctors:
|
| 664 |
+
item = {
|
| 665 |
+
"id": d.get("id"),
|
| 666 |
+
"fname": d.get("fname"),
|
| 667 |
+
"lname": d.get("lname"),
|
| 668 |
+
"brief": d.get("brief"),
|
| 669 |
+
"image": d.get("image"),
|
| 670 |
+
"created_at": d.get("created_at"),
|
| 671 |
+
"is_favorite": d.get("id") in fav_ids,
|
| 672 |
+
}
|
| 673 |
+
if only_favorites and not item["is_favorite"]:
|
| 674 |
+
continue
|
| 675 |
+
shaped.append(item)
|
| 676 |
|
| 677 |
+
return {"count": len(shaped), "data": shaped}
|
| 678 |
|
| 679 |
@app.get("/api/doctors/{doctor_id}/details")
|
| 680 |
def doctor_details(doctor_id: int):
|