Binrushd-Medical-Center commited on
Commit
f0e7930
·
verified ·
1 Parent(s): 990c720

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +47 -0
main.py CHANGED
@@ -657,3 +657,50 @@ def department_field(department_id: int, key: str):
657
  raise HTTPException(404, f"Field '{key}' not found")
658
 
659
  return {"id": department_id, "key": key, "value": value}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
657
  raise HTTPException(404, f"Field '{key}' not found")
658
 
659
  return {"id": department_id, "key": key, "value": value}
660
+
661
+ # ====== Branches ======
662
+
663
+ @app.get("/api/branches")
664
+ def list_branches_summary():
665
+ """
666
+ يرجّع ملخص الفروع من branches_summary.json
667
+ (id, name, brief, image)
668
+ """
669
+ path = BASE_DIR / "branches_summary.json"
670
+ if not path.exists():
671
+ raise HTTPException(500, "branches_summary.json not found")
672
+
673
+ try:
674
+ data = json.loads(path.read_text(encoding="utf-8"))
675
+ except json.JSONDecodeError:
676
+ raise HTTPException(500, "branches_summary.json contains invalid JSON")
677
+
678
+ payload = data.get("data", data)
679
+ return {"count": len(payload), "data": payload}
680
+
681
+
682
+ @app.get("/api/branches/{branch_id}")
683
+ def branch_details(branch_id: int):
684
+ """
685
+ يرجّع تفاصيل فرع واحد من branches_details.json
686
+ (العنوان، الإحداثيات، المواعيد، الإيميل، الدكاترة…)
687
+ """
688
+ path = BASE_DIR / "branches_details.json"
689
+ if not path.exists():
690
+ raise HTTPException(500, "branches_details.json not found")
691
+
692
+ try:
693
+ info = json.loads(path.read_text(encoding="utf-8"))
694
+ except json.JSONDecodeError:
695
+ raise HTTPException(500, "branches_details.json contains invalid JSON")
696
+
697
+ items = info.get("data", info)
698
+ if isinstance(items, list):
699
+ for it in items:
700
+ if it.get("id") == branch_id:
701
+ return {"message": "Branch Fetched Successfully", "data": it}
702
+ elif isinstance(items, dict) and str(branch_id) in items:
703
+ return {"message": "Branch Fetched Successfully", "data": items[str(branch_id)]}
704
+
705
+ raise HTTPException(404, f"Branch {branch_id} not found")
706
+