This commit is contained in:
2026-06-15 18:40:54 +08:00
parent 216726337b
commit 1ca02a119f
9 changed files with 193 additions and 119 deletions
+5 -6
View File
@@ -288,7 +288,7 @@ async def alipay_callback(request: Request, db: AsyncSession = Depends(get_db)):
return "success"
@router.get("/orders", response_model=list[PaymentOrderOut])
@router.get("/orders")
async def list_orders(
page: int = Query(1, ge=1),
page_size: int = Query(20, ge=1, le=100),
@@ -296,10 +296,10 @@ async def list_orders(
db: AsyncSession = Depends(get_db),
):
from app.services.payment import _check_and_expire_order
count_query = select(func.count(PaymentOrder.id)).where(PaymentOrder.user_id == current_user.id)
total = (await db.execute(count_query)).scalar() or 0
result = await db.execute(
select(PaymentOrder)
.where(PaymentOrder.user_id == current_user.id)
@@ -310,9 +310,8 @@ async def list_orders(
orders = result.scalars().all()
for o in orders:
await _check_and_expire_order(db, o)
from fastapi.responses import JSONResponse
return JSONResponse(content={"items": orders, "total": total})
return {"items": [PaymentOrderOut.model_validate(o) for o in orders], "total": total}
@router.get("/orders/{order_no}", response_model=PaymentOrderOut)