Browse Source

Merge branch 'master' of http://139.224.214.174:3000/jerry/webapp

jerry 2 months ago
parent
commit
61ac7642b5
3 changed files with 47 additions and 5 deletions
  1. 13 1
      app/api/router.py
  2. 30 1
      app/services/product_service.py
  3. 4 3
      app/services/schema_service.py

+ 13 - 1
app/api/router.py

@@ -952,7 +952,19 @@ async def vas_product_update(
     product = await ProductService.update(db, id, payload)
     return success(data=product)
 
-@public_router.get("/vas/product/list", summary="获取商品列表", tags=["Visafly签证系统"], response_model=ApiResponse[PageResponse[VasProductOut]])
+@public_router.get("/vas/product/list-enable", summary="获取商品列表", tags=["Visafly签证系统"], response_model=ApiResponse[PageResponse[VasProductOut]])
+async def vas_product_list(
+    country: str = Query("", description="目的国家"),
+    visa_type: str = Query("", description="签证类型"),
+    page: int = Query(0, description="第几页"),
+    size: int = Query(10, description="分页大小"),
+    keyword: str = Query("", description="查询条件"),
+    db: AsyncSession = Depends(get_db)
+):
+    products = await ProductService.list_enable_product(db, country, visa_type, page, size, keyword)
+    return success(data=products)
+
+@admin_required_router.get("/vas/product/list", summary="获取商品列表", tags=["Visafly签证系统"], response_model=ApiResponse[PageResponse[VasProductOut]])
 async def vas_product_list(
     country: str = Query("", description="目的国家"),
     visa_type: str = Query("", description="签证类型"),

+ 30 - 1
app/services/product_service.py

@@ -54,7 +54,7 @@ class ProductService:
         return rec
 
     @staticmethod
-    async def list_product(
+    async def list_enable_product(
         db: AsyncSession,
         country: str = None,
         visa_type: str = None,
@@ -83,3 +83,32 @@ class ProductService:
         )
 
         return await paginate(db, stmt, page, size)
+    
+    @staticmethod
+    async def list_product(
+        db: AsyncSession,
+        country: str = None,
+        visa_type: str = None,
+        page: int = 0,
+        size: int = 10,
+        keyword: str = None,
+    ):
+        # ⚠️ paginate / apply_keyword_search 仍然基于 Query
+        # 如果你当前 paginate 是同步实现,这里保持与你原项目一致
+
+        stmt = select(VasProduct)
+
+        if country:
+            stmt = stmt.where(VasProduct.country == country)
+
+        if visa_type:
+            stmt = stmt.where(VasProduct.visa_type == visa_type)
+
+        stmt = apply_keyword_search_stmt(
+            stmt=stmt,
+            model=VasProduct,
+            keyword=keyword,
+            fields=["title", "provider", "description"],
+        )
+
+        return await paginate(db, stmt, page, size)

+ 4 - 3
app/services/schema_service.py

@@ -16,7 +16,7 @@ class SchemaService:
         db: AsyncSession,
         data: VasSchemaCreate,
     ) -> VasSchema:
-        rec = VasSchema(**data.dict())
+        rec = VasSchema(**data.model_dump(by_alias=True)) 
         db.add(rec)
         await db.commit()
         await db.refresh(rec)
@@ -43,8 +43,9 @@ class SchemaService:
         obj = (await db.execute(stmt)).scalar_one_or_none()
         if not obj:
             raise NotFoundError("Schema not exist")
-
-        for k, v in data.dict(exclude_unset=True).items():
+        
+        update_data = data.model_dump(exclude_unset=True, by_alias=True)
+        for k, v in update_data.items():
             setattr(obj, k, v)
 
         await db.commit()