Update main.py
Browse files
main.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException, BackgroundTasks
|
|
|
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import Optional, Dict
|
|
@@ -365,6 +366,22 @@ async def send_email(payload: EmailPayload):
|
|
| 365 |
except Exception as e:
|
| 366 |
raise HTTPException(status_code=500, detail=f"郵件發送失敗: {str(e)}")
|
| 367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
@app.get("/api/inventory/{query_date}")
|
| 369 |
async def get_inventory(query_date: str):
|
| 370 |
if not supabase: return {}
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException, BackgroundTasks
|
| 2 |
+
from fastapi.responses import RedirectResponse
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from typing import Optional, Dict
|
|
|
|
| 366 |
except Exception as e:
|
| 367 |
raise HTTPException(status_code=500, detail=f"郵件發送失敗: {str(e)}")
|
| 368 |
|
| 369 |
+
@app.get("/api/booking/action")
|
| 370 |
+
async def booking_action(action: str, id: str):
|
| 371 |
+
"""用戶點擊確認/取消連結後,更新 Supabase 再導向回前端。"""
|
| 372 |
+
if not supabase:
|
| 373 |
+
raise HTTPException(status_code=500, detail="資料庫未設定")
|
| 374 |
+
if action not in ("confirm", "cancel"):
|
| 375 |
+
raise HTTPException(status_code=400, detail="無效的動作")
|
| 376 |
+
|
| 377 |
+
status_map = {"confirm": "顧客已確認", "cancel": "顧客已取消"}
|
| 378 |
+
try:
|
| 379 |
+
supabase.table("bookings").update({"status": status_map[action]}).eq("id", id).execute()
|
| 380 |
+
except Exception as e:
|
| 381 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 382 |
+
|
| 383 |
+
return RedirectResponse(url=f"{RETURN_URL}?action={action}", status_code=302)
|
| 384 |
+
|
| 385 |
@app.get("/api/inventory/{query_date}")
|
| 386 |
async def get_inventory(query_date: str):
|
| 387 |
if not supabase: return {}
|