Binrushd-Medical-Center commited on
Commit
9db0aca
·
verified ·
1 Parent(s): 0e8d333

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -11
main.py CHANGED
@@ -1103,27 +1103,42 @@ def create_booking(body: BookingIn, payload=Depends(require_scopes(["user"]))):
1103
  # ====== My Bookings ======
1104
  from typing import List
1105
 
1106
- @app.get("/api/my-bookings", response_model=List[BookingOut])
1107
- def my_bookings(
1108
- payload=Depends(require_scopes(["user"])),
1109
- limit: int = 50, offset: int = 0, order: str = "created_at.desc"
 
 
 
1110
  ):
1111
  """
1112
- يرجّع حجوزات المستخدم الحالي.
1113
- يمكن تغيير الترتيب بإرسال order مثل 'created_at.asc'
 
1114
  """
1115
- me = get_user_by_email_or_404(payload["sub"])
 
1116
 
1117
  params = {
1118
- **eq("user_id", me["id"]),
1119
- "select": "id,booking_code,user_id,doctor_id,branch_id,offer_id,appointment_iso,notes,referral_source,status,created_at",
1120
  "order": order,
1121
  "limit": str(limit),
1122
  "offset": str(offset),
1123
  }
1124
- rows = supa_select("bookings", params)
1125
- return rows
1126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1127
  # ====== Referral Sources (static list) ======
1128
  @app.get("/api/referral-sources")
1129
  def referral_sources():
 
1103
  # ====== My Bookings ======
1104
  from typing import List
1105
 
1106
+ @app.get("/api/bookings/by-contact")
1107
+ def bookings_by_contact(
1108
+ client_mobile: Optional[str] = None,
1109
+ client_email: Optional[str] = None,
1110
+ limit: int = 100,
1111
+ offset: int = 0,
1112
+ order: str = "created_at.desc",
1113
  ):
1114
  """
1115
+ يرجّع حجوزات العميل عن طريق client_mobile و/أو client_email.
1116
+ - لو الاتنين اتبعتوا: هنطبّق فلتر AND (لازم يطابقوا معًا).
1117
+ - لو واحد منهم اتبعت: هنفلتر بيه لوحده.
1118
  """
1119
+ if not client_mobile and not client_email:
1120
+ raise HTTPException(400, "أرسل client_mobile أو client_email على الأقل")
1121
 
1122
  params = {
1123
+ "select": "*",
 
1124
  "order": order,
1125
  "limit": str(limit),
1126
  "offset": str(offset),
1127
  }
 
 
1128
 
1129
+ # AND filters (لو الاتنين مبعوتين)
1130
+ if client_mobile:
1131
+ params.update(eq("client_mobile", client_mobile))
1132
+ if client_email:
1133
+ params.update(eq("client_email", client_email))
1134
+
1135
+ rows = supa_select("bookings", params)
1136
+ return {
1137
+ "message": "Bookings fetched successfully",
1138
+ "count": len(rows),
1139
+ "data": rows
1140
+ }
1141
+
1142
  # ====== Referral Sources (static list) ======
1143
  @app.get("/api/referral-sources")
1144
  def referral_sources():