feat: add Create Product and CRUD actions to vendor-products page
- Add "Create Product" button in header - Update actions column to View, Edit, Delete - Add create/edit pages with forms and vendor selector - Add POST/PATCH API endpoints for vendor products - Add create_product and update_product service methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,10 +25,13 @@ from models.schema.vendor_product import (
|
||||
CatalogVendor,
|
||||
CatalogVendorsResponse,
|
||||
RemoveProductResponse,
|
||||
VendorProductCreate,
|
||||
VendorProductCreateResponse,
|
||||
VendorProductDetail,
|
||||
VendorProductListItem,
|
||||
VendorProductListResponse,
|
||||
VendorProductStats,
|
||||
VendorProductUpdate,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/vendor-products")
|
||||
@@ -109,6 +112,37 @@ def get_vendor_product_detail(
|
||||
return VendorProductDetail(**product)
|
||||
|
||||
|
||||
@router.post("", response_model=VendorProductCreateResponse)
|
||||
def create_vendor_product(
|
||||
data: VendorProductCreate,
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""Create a new vendor product."""
|
||||
product = vendor_product_service.create_product(db, data.model_dump())
|
||||
db.commit() # ✅ ARCH: Commit at API level for transaction control
|
||||
return VendorProductCreateResponse(
|
||||
id=product.id, message="Product created successfully"
|
||||
)
|
||||
|
||||
|
||||
@router.patch("/{product_id}", response_model=VendorProductDetail)
|
||||
def update_vendor_product(
|
||||
product_id: int,
|
||||
data: VendorProductUpdate,
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""Update a vendor product."""
|
||||
# Only include fields that were explicitly set
|
||||
update_data = data.model_dump(exclude_unset=True)
|
||||
vendor_product_service.update_product(db, product_id, update_data)
|
||||
db.commit() # ✅ ARCH: Commit at API level for transaction control
|
||||
# Return the updated product detail
|
||||
product = vendor_product_service.get_product_detail(db, product_id)
|
||||
return VendorProductDetail(**product)
|
||||
|
||||
|
||||
@router.delete("/{product_id}", response_model=RemoveProductResponse)
|
||||
def remove_vendor_product(
|
||||
product_id: int,
|
||||
|
||||
Reference in New Issue
Block a user