Update app.py
Browse files
app.py
CHANGED
|
@@ -833,25 +833,25 @@ async def payment_callback(request: Request):
|
|
| 833 |
@app.get("/track_order/{order_id}")
|
| 834 |
async def track_order(order_id: str):
|
| 835 |
|
| 836 |
-
async with async_session() as session
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
if __name__ == "__main__":
|
| 856 |
import uvicorn
|
| 857 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 833 |
@app.get("/track_order/{order_id}")
|
| 834 |
async def track_order(order_id: str):
|
| 835 |
|
| 836 |
+
async with async_session() as session:
|
| 837 |
+
result = await session.execute(
|
| 838 |
+
select(OrderTracking)
|
| 839 |
+
.where(OrderTracking.order_id == order_id)
|
| 840 |
+
.order_by(OrderTracking.timestamp)
|
| 841 |
+
)
|
| 842 |
+
tracking_updates = result.scalars().all()
|
| 843 |
+
if tracking_updates:
|
| 844 |
+
response = []
|
| 845 |
+
for update in tracking_updates:
|
| 846 |
+
response.append({
|
| 847 |
+
"status": update.status,
|
| 848 |
+
"message": update.message,
|
| 849 |
+
"timestamp": update.timestamp.isoformat(),
|
| 850 |
+
})
|
| 851 |
+
return JSONResponse(content=response)
|
| 852 |
+
else:
|
| 853 |
+
raise HTTPException(status_code=404, detail="No tracking information found for this order.")
|
| 854 |
+
|
| 855 |
if __name__ == "__main__":
|
| 856 |
import uvicorn
|
| 857 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|