From fe41fcc12bb928a69c400b27070dd904be016673 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Sat, 11 Jan 2025 23:37:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E4=BC=A0=E5=85=A5=E5=8F=82=E6=95=B0me?= =?UTF-8?q?rchantid=20=E8=BF=9B=E8=A1=8C=E5=AD=98=E5=9C=A8=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/merchant_product.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/api/endpoints/merchant_product.py b/app/api/endpoints/merchant_product.py index 3af4927..7ae1500 100644 --- a/app/api/endpoints/merchant_product.py +++ b/app/api/endpoints/merchant_product.py @@ -11,16 +11,26 @@ from app.models.database import get_db from app.api.deps import get_admin_user from app.models.user import UserDB from app.core.response import success_response, error_response, ResponseModel +from app.models.merchant import MerchantDB router = APIRouter() @router.post("", response_model=ResponseModel) -async def create_product( +async def create_merchant_product( product: MerchantProductCreate, db: Session = Depends(get_db), admin: UserDB = Depends(get_admin_user) ): """创建商家产品(管理员)""" + + # 检查商家是否存在 + merchant = db.query(MerchantDB).filter( + MerchantDB.id == product.merchant_id + ).first() + + if not merchant: + return error_response(code=404, message="商家不存在") + db_product = MerchantProductDB(**product.model_dump()) db.add(db_product)