|
@@ -9,7 +9,8 @@ from app.core.config import settings
|
|
|
from app.core.logger import get_logger
|
|
from app.core.logger import get_logger
|
|
|
from app.core.database_loader import get_db_connection
|
|
from app.core.database_loader import get_db_connection
|
|
|
from app.utils.scheme import (
|
|
from app.utils.scheme import (
|
|
|
- CardDetailResponse, CardListDetailResponse, CardType, SortBy, SortOrder
|
|
|
|
|
|
|
+ CardDetailResponse, CardListDetailResponse, CardType, SortBy,
|
|
|
|
|
+ SortOrder, CardListResponseWrapper, CardListWithTotal
|
|
|
)
|
|
)
|
|
|
from app.crud import crud_card
|
|
from app.crud import crud_card
|
|
|
|
|
|
|
@@ -132,7 +133,7 @@ def list_cards_detailed(
|
|
|
):
|
|
):
|
|
|
"""获取卡牌的基础信息列表,支持按名称、类型筛选,以及多字段排序和分页。"""
|
|
"""获取卡牌的基础信息列表,支持按名称、类型筛选,以及多字段排序和分页。"""
|
|
|
if page_num is not None:
|
|
if page_num is not None:
|
|
|
- skip = (page_num-1) * limit
|
|
|
|
|
|
|
+ skip = (page_num - 1) * limit
|
|
|
try:
|
|
try:
|
|
|
cards_with_images = crud_card.get_card_list_with_images(
|
|
cards_with_images = crud_card.get_card_list_with_images(
|
|
|
db_conn,
|
|
db_conn,
|
|
@@ -152,6 +153,66 @@ def list_cards_detailed(
|
|
|
raise HTTPException(status_code=500, detail="获取数据列表失败。")
|
|
raise HTTPException(status_code=500, detail="获取数据列表失败。")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+@router.get("/card_list_filter", response_model=CardListResponseWrapper, summary="获取卡牌列表和总数")
|
|
|
|
|
+def card_list_filter(
|
|
|
|
|
+ card_id: Optional[int] = Query(None, description="筛选:卡牌ID"),
|
|
|
|
|
+ card_name: Optional[str] = Query(None, description="筛选:卡牌名称"),
|
|
|
|
|
+ card_type: Optional[CardType] = Query(None, description="筛选:卡牌类型"),
|
|
|
|
|
+ is_edited: Optional[bool] = Query(None, description="筛选:是否已编辑"),
|
|
|
|
|
+
|
|
|
|
|
+ min_detection_score: Optional[float] = Query(None, ge=0, le=10),
|
|
|
|
|
+ max_detection_score: Optional[float] = Query(None, ge=0, le=10),
|
|
|
|
|
+ min_modified_score: Optional[float] = Query(None, ge=0, le=10),
|
|
|
|
|
+ max_modified_score: Optional[float] = Query(None, ge=0, le=10),
|
|
|
|
|
+
|
|
|
|
|
+ created_start: Optional[date] = Query(None),
|
|
|
|
|
+ created_end: Optional[date] = Query(None),
|
|
|
|
|
+ updated_start: Optional[date] = Query(None),
|
|
|
|
|
+ updated_end: Optional[date] = Query(None),
|
|
|
|
|
+
|
|
|
|
|
+ sort_by: SortBy = Query(SortBy.updated_at),
|
|
|
|
|
+ sort_order: SortOrder = Query(SortOrder.desc),
|
|
|
|
|
+ skip: int = Query(0, ge=0),
|
|
|
|
|
+ page_num: int = Query(None, ge=0),
|
|
|
|
|
+ limit: int = Query(100, ge=1, le=1000),
|
|
|
|
|
+ db_conn: PooledMySQLConnection = db_dependency
|
|
|
|
|
+):
|
|
|
|
|
+ """
|
|
|
|
|
+ 获取卡牌列表,返回格式包含 total 和 list。
|
|
|
|
|
+ 结构: { "data": { "total": 100, "list": [...] } }
|
|
|
|
|
+ """
|
|
|
|
|
+ if page_num is not None:
|
|
|
|
|
+ skip = page_num * limit
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ result = crud_card.get_card_list_and_count(
|
|
|
|
|
+ db_conn,
|
|
|
|
|
+ card_id, card_name, card_type, is_edited,
|
|
|
|
|
+ min_detection_score, max_detection_score,
|
|
|
|
|
+ min_modified_score, max_modified_score,
|
|
|
|
|
+ created_start, created_end,
|
|
|
|
|
+ updated_start, updated_end,
|
|
|
|
|
+ sort_by, sort_order, skip, limit
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # 组装返回数据,注意这里要进行 model_validate 转换 list 中的每一项
|
|
|
|
|
+ # 1. 先把 list 里的字典转成 Pydantic 对象
|
|
|
|
|
+ validated_list = [CardListDetailResponse.model_validate(c) for c in result['list']]
|
|
|
|
|
+
|
|
|
|
|
+ # 2. 构造 data 部分
|
|
|
|
|
+ data_content = CardListWithTotal(
|
|
|
|
|
+ total=result['total'],
|
|
|
|
|
+ list=validated_list
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # 3. 构造最外层包装
|
|
|
|
|
+ return CardListResponseWrapper(data=data_content)
|
|
|
|
|
+
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(f"查询卡牌列表(带总数)失败: {e}")
|
|
|
|
|
+ raise HTTPException(status_code=500, detail="获取数据列表失败。")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@router.delete("/delete/{id}", status_code=200, summary="删除卡牌及其所有关联图片")
|
|
@router.delete("/delete/{id}", status_code=200, summary="删除卡牌及其所有关联图片")
|
|
|
def delete_card(id: int, db_conn: PooledMySQLConnection = db_dependency):
|
|
def delete_card(id: int, db_conn: PooledMySQLConnection = db_dependency):
|
|
|
"""
|
|
"""
|