Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,52 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
-
from typing import List
|
| 4 |
-
import pandas as pd
|
| 5 |
-
|
| 6 |
-
app = FastAPI()
|
| 7 |
-
|
| 8 |
-
# نموذج بيانات الشكوى
|
| 9 |
-
class Complaint(BaseModel):
|
| 10 |
-
title: str
|
| 11 |
-
description: str
|
| 12 |
-
status: str = "Open"
|
| 13 |
-
|
| 14 |
-
# قائمة لتخزين الشكاوى مؤقتًا (بديل عن قاعدة بيانات)
|
| 15 |
-
complaints_db = []
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
global
|
| 21 |
-
new_complaint = {
|
| 22 |
-
"id":
|
| 23 |
-
"title": complaint.title,
|
| 24 |
-
"description": complaint.description,
|
| 25 |
-
"status": complaint.status
|
| 26 |
-
}
|
| 27 |
-
complaints_db.append(new_complaint)
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
if
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
if not complaints_db:
|
| 48 |
-
raise HTTPException(status_code=404, detail="⚠️ لا توجد بيانات للتصدير.")
|
| 49 |
-
|
| 50 |
-
df = pd.DataFrame(complaints_db)
|
| 51 |
-
df.to_csv("complaints_export.csv", index=False)
|
| 52 |
-
return {"message": "✅ تم تصدير الشكاوى بنجاح! يمكنك تحميل الملف من السيرفر."}
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import List
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# نموذج بيانات الشكوى
|
| 9 |
+
class Complaint(BaseModel):
|
| 10 |
+
title: str
|
| 11 |
+
description: str
|
| 12 |
+
status: str = "Open"
|
| 13 |
+
|
| 14 |
+
# قائمة لتخزين الشكاوى مؤقتًا (بديل عن قاعدة بيانات)
|
| 15 |
+
complaints_db = []
|
| 16 |
+
|
| 17 |
+
@app.post("/complaints/")
|
| 18 |
+
def create_complaint(complaint: Complaint):
|
| 19 |
+
"""إرسال شكوى جديدة"""
|
| 20 |
+
complaint_id = len(complaints_db) + 1 # تجنب استخدام global
|
| 21 |
+
new_complaint = {
|
| 22 |
+
"id": complaint_id,
|
| 23 |
+
"title": complaint.title,
|
| 24 |
+
"description": complaint.description,
|
| 25 |
+
"status": complaint.status
|
| 26 |
+
}
|
| 27 |
+
complaints_db.append(new_complaint)
|
| 28 |
+
return {"message": "✅ تم إرسال الشكوى بنجاح!", "complaint": new_complaint}
|
| 29 |
+
|
| 30 |
+
@app.get("/complaints/")
|
| 31 |
+
def get_complaints():
|
| 32 |
+
"""عرض جميع الشكاوى"""
|
| 33 |
+
return complaints_db if complaints_db else []
|
| 34 |
+
|
| 35 |
+
@app.put("/complaints/{complaint_id}/status/")
|
| 36 |
+
def update_complaint_status(complaint_id: int, new_status: str):
|
| 37 |
+
"""تحديث حالة الشكوى"""
|
| 38 |
+
for complaint in complaints_db:
|
| 39 |
+
if complaint["id"] == complaint_id:
|
| 40 |
+
complaint["status"] = new_status
|
| 41 |
+
return {"message": "✅ تم تحديث حالة الشكوى!"}
|
| 42 |
+
raise HTTPException(status_code=404, detail="⚠️ الشكوى غير موجودة")
|
| 43 |
+
|
| 44 |
+
@app.get("/export/")
|
| 45 |
+
def export_complaints():
|
| 46 |
+
"""تصدير الشكاوى إلى CSV"""
|
| 47 |
+
if not complaints_db:
|
| 48 |
+
raise HTTPException(status_code=404, detail="⚠️ لا توجد بيانات للتصدير.")
|
| 49 |
+
|
| 50 |
+
df = pd.DataFrame(complaints_db)
|
| 51 |
+
df.to_csv("complaints_export.csv", index=False)
|
| 52 |
+
return {"message": "✅ تم تصدير الشكاوى بنجاح! يمكنك تحميل الملف من السيرفر."}
|