c1ce109f13
- 新增 OrderRecord 模型 (user_id, platform, store_name, dishes, order_date, price, original_price, savings) - 新增 order_record schema (OrderRecordOut + OrderListResponse) - 新增 CRUD: get_records_page 按 order_date DESC 分页查询 - 新增 /api/v1/user/records 路由, 需 Bearer token 鉴权, 支持 page/size 参数 - Alembic 迁移: add order_record table - platform 支持: meituan_waimai / taobao_shanguang / jd_waimai / meituan / taobao / jd - dishes 字段 DB 存 JSON 字符串, 接口返回 list[str] Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import logging
|
|
|
|
from fastapi import APIRouter, Query
|
|
|
|
from app.api.deps import CurrentUser, DbSession
|
|
from app.crud import order_record as crud_order
|
|
from app.schemas.order_record import OrderListResponse, OrderRecordOut
|
|
|
|
logger = logging.getLogger("shagua.api.user")
|
|
|
|
router = APIRouter(prefix="/api/v1/user", tags=["user"])
|
|
|
|
|
|
@router.get("/records", response_model=OrderListResponse, summary="分页查询当前用户的订单记录")
|
|
def list_records(
|
|
user: CurrentUser,
|
|
db: DbSession,
|
|
page: int = Query(1, ge=1),
|
|
size: int = Query(20, ge=1, le=100),
|
|
) -> OrderListResponse:
|
|
rows, has_next = crud_order.get_records_page(db, user_id=user.id, page=page, size=size)
|
|
records = [
|
|
OrderRecordOut(
|
|
id=r.id,
|
|
platform=r.platform,
|
|
store_name=r.store_name,
|
|
dishes=json.loads(r.dishes) if r.dishes else [],
|
|
order_date=r.order_date,
|
|
price=r.price,
|
|
original_price=r.original_price,
|
|
savings=r.savings,
|
|
)
|
|
for r in rows
|
|
]
|
|
return OrderListResponse(records=records, has_next=has_next, page=page)
|