Update main.py
Browse files
main.py
CHANGED
|
@@ -1105,51 +1105,36 @@ from typing import Optional
|
|
| 1105 |
|
| 1106 |
@app.get("/api/bookings/by-contact")
|
| 1107 |
def bookings_by_contact(
|
| 1108 |
-
payload=Depends(require_scopes(["user"])),
|
| 1109 |
-
client_mobile: Optional[str] = None,
|
| 1110 |
-
client_email: Optional[str] = None,
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
|
|
|
| 1114 |
):
|
| 1115 |
"""
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
- لو مبعتش حاجة → نستخدم إيميل التوكن كـ default.
|
| 1121 |
-
لازال يتطلّب Bearer token بصلاحية user.
|
| 1122 |
"""
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
|
| 1126 |
params = {
|
| 1127 |
-
"select":
|
| 1128 |
"order": order,
|
| 1129 |
"limit": str(limit),
|
| 1130 |
"offset": str(offset),
|
| 1131 |
}
|
| 1132 |
-
|
| 1133 |
-
# طبّق الفلاتر حسب اللي مبعوت
|
| 1134 |
-
if client_mobile and effective_email:
|
| 1135 |
-
# AND: الموبايل + الإيميل
|
| 1136 |
-
params.update(eq("client_mobile", client_mobile))
|
| 1137 |
-
params.update(eq("client_email", effective_email))
|
| 1138 |
-
elif client_mobile:
|
| 1139 |
params.update(eq("client_mobile", client_mobile))
|
| 1140 |
-
|
| 1141 |
-
params.update(eq("client_email",
|
| 1142 |
-
else:
|
| 1143 |
-
# نظريًا مش هنوصل هنا لأن عندنا توكن، بس للاحتياط
|
| 1144 |
-
raise HTTPException(400, "أرسل client_mobile أو client_email أو استخدم توكن صالح")
|
| 1145 |
|
| 1146 |
rows = supa_select("bookings", params)
|
| 1147 |
-
return {
|
| 1148 |
-
"message": "Bookings fetched successfully",
|
| 1149 |
-
"count": len(rows),
|
| 1150 |
-
"data": rows
|
| 1151 |
-
}
|
| 1152 |
-
|
| 1153 |
|
| 1154 |
# ====== Referral Sources (static list) ======
|
| 1155 |
@app.get("/api/referral-sources")
|
|
|
|
| 1105 |
|
| 1106 |
@app.get("/api/bookings/by-contact")
|
| 1107 |
def bookings_by_contact(
|
| 1108 |
+
payload=Depends(require_scopes(["user"])), # لازم توكن دخول عادي
|
| 1109 |
+
client_mobile: Optional[str] = Query(None),
|
| 1110 |
+
client_email: Optional[str] = Query(None),
|
| 1111 |
+
select: str = Query("*"),
|
| 1112 |
+
order: str = Query("created_at.desc"),
|
| 1113 |
+
limit: int = Query(100, ge=1, le=1000),
|
| 1114 |
+
offset: int = Query(0, ge=0),
|
| 1115 |
):
|
| 1116 |
"""
|
| 1117 |
+
مطابق لطريقة Supabase REST:
|
| 1118 |
+
- يدعم select, order, limit, offset
|
| 1119 |
+
- client_mobile و/أو client_email بفلترة eq
|
| 1120 |
+
- AND logic لو الاتنين مُرسلين
|
|
|
|
|
|
|
| 1121 |
"""
|
| 1122 |
+
if not client_mobile and not client_email:
|
| 1123 |
+
raise HTTPException(400, "أرسل client_mobile أو client_email على الأقل")
|
| 1124 |
|
| 1125 |
params = {
|
| 1126 |
+
"select": select,
|
| 1127 |
"order": order,
|
| 1128 |
"limit": str(limit),
|
| 1129 |
"offset": str(offset),
|
| 1130 |
}
|
| 1131 |
+
if client_mobile:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1132 |
params.update(eq("client_mobile", client_mobile))
|
| 1133 |
+
if client_email:
|
| 1134 |
+
params.update(eq("client_email", client_email))
|
|
|
|
|
|
|
|
|
|
| 1135 |
|
| 1136 |
rows = supa_select("bookings", params)
|
| 1137 |
+
return {"message": "Bookings fetched successfully", "count": len(rows), "data": rows}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1138 |
|
| 1139 |
# ====== Referral Sources (static list) ======
|
| 1140 |
@app.get("/api/referral-sources")
|