Binrushd-Medical-Center commited on
Commit
6462954
·
verified ·
1 Parent(s): a5949ae

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -17
main.py CHANGED
@@ -998,7 +998,7 @@ def get_about():
998
  # ====== Reservations ======
999
 
1000
  # ====== Bookings Schemas ======
1001
- from pydantic import BaseModel, Field
1002
  from typing import Optional, Literal
1003
 
1004
  class BookingIn(BaseModel):
@@ -1007,10 +1007,10 @@ class BookingIn(BaseModel):
1007
  client_mobile: Optional[str] = None
1008
  client_email: Optional[str] = None
1009
 
1010
- # بدّلنا الـ labels بـ IDs
1011
- doctor_id: int = Field(..., gt=0)
1012
- branch_id: int = Field(..., gt=0)
1013
- offer_id: Optional[int] = Field(None, gt=0)
1014
 
1015
  # باقي الحقول
1016
  appointment_iso: Optional[str] = None
@@ -1024,12 +1024,15 @@ class BookingIn(BaseModel):
1024
  class BookingOut(BaseModel):
1025
  id: int
1026
  booking_code: str
 
 
 
 
 
 
1027
  client_name: Optional[str]
1028
  client_mobile: Optional[str]
1029
  client_email: Optional[str]
1030
- doctor_label: Optional[str]
1031
- branch_label: Optional[str]
1032
- offer_label: Optional[str]
1033
  appointment_iso: Optional[str]
1034
  notes: Optional[str]
1035
  referral_source: str
@@ -1212,21 +1215,13 @@ def validate_fk_or_400(doctor_id: int, branch_id: int, offer_id: Optional[int]):
1212
 
1213
  @app.post("/api/bookings", response_model=BookingCreateResponse)
1214
  def create_booking(body: BookingIn, payload=Depends(require_scopes(["user"]))):
1215
- """
1216
- يسجّل بيانات الحجز في جدول bookings باستخدام IDs حقيقية:
1217
- doctor_id, branch_id, (offer_id اختياري)
1218
- """
1219
- # تأكيد أن طالب العملية مستخدم صالح
1220
  _ = get_user_by_email_or_404(payload["sub"])
1221
 
1222
- # تحقّق من صحة المراجع قبل الإدراج
1223
- validate_fk_or_400(doctor_id=body.doctor_id, branch_id=body.branch_id, offer_id=body.offer_id)
1224
-
1225
  rec = {
1226
  "booking_code": gen_booking_code(),
1227
  "doctor_id": body.doctor_id,
1228
  "branch_id": body.branch_id,
1229
- "offer_id": body.offer_id, # قد تكون None
1230
  "appointment_iso": body.appointment_iso,
1231
  "notes": body.notes,
1232
  "referral_source": body.referral_source,
 
998
  # ====== Reservations ======
999
 
1000
  # ====== Bookings Schemas ======
1001
+ from pydantic import BaseModel
1002
  from typing import Optional, Literal
1003
 
1004
  class BookingIn(BaseModel):
 
1007
  client_mobile: Optional[str] = None
1008
  client_email: Optional[str] = None
1009
 
1010
+ # IDs بدل labels
1011
+ doctor_id: int
1012
+ branch_id: int
1013
+ offer_id: Optional[int] = None # اختياري
1014
 
1015
  # باقي الحقول
1016
  appointment_iso: Optional[str] = None
 
1024
  class BookingOut(BaseModel):
1025
  id: int
1026
  booking_code: str
1027
+
1028
+ # الأعمدة الفعلية في الجدول الآن
1029
+ doctor_id: int
1030
+ branch_id: int
1031
+ offer_id: Optional[int] = None
1032
+
1033
  client_name: Optional[str]
1034
  client_mobile: Optional[str]
1035
  client_email: Optional[str]
 
 
 
1036
  appointment_iso: Optional[str]
1037
  notes: Optional[str]
1038
  referral_source: str
 
1215
 
1216
  @app.post("/api/bookings", response_model=BookingCreateResponse)
1217
  def create_booking(body: BookingIn, payload=Depends(require_scopes(["user"]))):
 
 
 
 
 
1218
  _ = get_user_by_email_or_404(payload["sub"])
1219
 
 
 
 
1220
  rec = {
1221
  "booking_code": gen_booking_code(),
1222
  "doctor_id": body.doctor_id,
1223
  "branch_id": body.branch_id,
1224
+ "offer_id": body.offer_id,
1225
  "appointment_iso": body.appointment_iso,
1226
  "notes": body.notes,
1227
  "referral_source": body.referral_source,