diff --git a/backend/app/routers/collections.py b/backend/app/routers/collections.py index 4df0b5c..983ba1c 100644 --- a/backend/app/routers/collections.py +++ b/backend/app/routers/collections.py @@ -304,6 +304,34 @@ def get_stats( } +@router.get("/by-user/{user_id}") +def get_collections_by_user( + user_id: str, + current_user: User = Depends(get_current_user), + db: Session = Depends(get_db) +): + """获取指定用户的所有藏品(管理员专用)""" + if current_user.role != "admin": + raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问") + + collections = db.query(Collection).filter( + Collection.f99_91_user_id == user_id + ).all() + + result = [] + for c in collections: + result.append({ + "f99_90_id": c.f99_90_id, + "f01_01_name": c.f01_01_name, + "f02_10_prefix_serial": c.f02_10_prefix_serial, + "f02_11_version": c.f02_11_version, + "f01_04_status": c.f01_04_status, + "f05_40_cost_price": c.f05_40_cost_price, + "f99_92_created_at": c.f99_92_created_at.isoformat() if c.f99_92_created_at else None + }) + + return result + @router.get("/{collection_id}") def get_collection( collection_id: str,