Update main.py
Browse files
main.py
CHANGED
|
@@ -704,7 +704,7 @@ def branch_details(branch_id: int):
|
|
| 704 |
|
| 705 |
raise HTTPException(404, f"Branch {branch_id} not found")
|
| 706 |
|
| 707 |
-
# ====== Blog
|
| 708 |
|
| 709 |
@app.get("/api/blog")
|
| 710 |
def list_blog_summary():
|
|
@@ -747,3 +747,58 @@ def blog_post_details(post_id: int):
|
|
| 747 |
return {"message": "Post Fetched Successfully", "data": items[str(post_id)]}
|
| 748 |
|
| 749 |
raise HTTPException(404, f"Post {post_id} not found")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 704 |
|
| 705 |
raise HTTPException(404, f"Branch {branch_id} not found")
|
| 706 |
|
| 707 |
+
# ====== Blog ======
|
| 708 |
|
| 709 |
@app.get("/api/blog")
|
| 710 |
def list_blog_summary():
|
|
|
|
| 747 |
return {"message": "Post Fetched Successfully", "data": items[str(post_id)]}
|
| 748 |
|
| 749 |
raise HTTPException(404, f"Post {post_id} not found")
|
| 750 |
+
|
| 751 |
+
# ====== Offers ======
|
| 752 |
+
|
| 753 |
+
@app.get("/api/offers")
|
| 754 |
+
def list_offers():
|
| 755 |
+
"""
|
| 756 |
+
ูุฑุฌูุน ูู ุงูุนุฑูุถ (offers + campaigns) ูู
ุง ูู ู
ู ู
ูู offers.json
|
| 757 |
+
"""
|
| 758 |
+
path = BASE_DIR / "offers.json"
|
| 759 |
+
if not path.exists():
|
| 760 |
+
raise HTTPException(500, "offers.json not found")
|
| 761 |
+
|
| 762 |
+
try:
|
| 763 |
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
| 764 |
+
except json.JSONDecodeError:
|
| 765 |
+
raise HTTPException(500, "offers.json contains invalid JSON")
|
| 766 |
+
|
| 767 |
+
# ูู ุงูู
ูู ุจููุณ ุงูุจููุฉ ุงูู
ุฑุณูุฉ (message + data) ูุฑุฌูุนู ูู
ุง ูู:
|
| 768 |
+
if isinstance(raw, dict) and "data" in raw:
|
| 769 |
+
return raw
|
| 770 |
+
|
| 771 |
+
# fallback ุจุณูุท
|
| 772 |
+
return {"message": "Offers Fetched Successfully", "data": raw}
|
| 773 |
+
|
| 774 |
+
|
| 775 |
+
@app.get("/api/offers/{item_id}")
|
| 776 |
+
def get_offer_by_id(item_id: int):
|
| 777 |
+
"""
|
| 778 |
+
ูุฑุฌูุน ุนูุตุฑ ูุงุญุฏ ุจุงูู id โ ูุจุญุซ ุฃููุงู ูู campaigns ุซู
ูู offers.
|
| 779 |
+
"""
|
| 780 |
+
path = BASE_DIR / "offers.json"
|
| 781 |
+
if not path.exists():
|
| 782 |
+
raise HTTPException(500, "offers.json not found")
|
| 783 |
+
|
| 784 |
+
try:
|
| 785 |
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
| 786 |
+
except json.JSONDecodeError:
|
| 787 |
+
raise HTTPException(500, "offers.json contains invalid JSON")
|
| 788 |
+
|
| 789 |
+
payload = raw.get("data", raw) if isinstance(raw, dict) else {}
|
| 790 |
+
campaigns = payload.get("campaigns", []) if isinstance(payload, dict) else []
|
| 791 |
+
offers = payload.get("offers", []) if isinstance(payload, dict) else []
|
| 792 |
+
|
| 793 |
+
# ุฏูุฑ ูู ุงูู campaigns
|
| 794 |
+
for c in campaigns:
|
| 795 |
+
if c.get("id") == item_id:
|
| 796 |
+
return {"message": "Campaign Fetched Successfully", "data": c}
|
| 797 |
+
|
| 798 |
+
# ุฏูุฑ ูู ุงูู offers
|
| 799 |
+
for o in offers:
|
| 800 |
+
if o.get("id") == item_id:
|
| 801 |
+
return {"message": "Offer Fetched Successfully", "data": o}
|
| 802 |
+
|
| 803 |
+
raise HTTPException(404, f"Item with id={item_id} not found")
|
| 804 |
+
|