@router.put("/{product_id}")
async def update_product(product_id: str, product: Product):
result = db.products.update_one(
{"_id": ObjectId(product_id)},
{"$set": product.model_dump()}
)
if result.matched_count == 0:
raise HTTPException(
status_code=404,
detail="Product not found"
)
return {
"message": "Product updated successfully"
}
#delete
@router.delete("/{product_id}")
async def delete_product(product_id: str):
result = db.products.delete_one(
{"_id": ObjectId(product_id)}
)
if result.deleted_count == 0:
raise HTTPException(
status_code=404,
detail="Product not found"
)
return {
"message": "Product deleted successfully"
}