#9 Delete Product box now available

This commit is contained in:
2024-02-08 19:58:49 +00:00
parent b49022f7f9
commit b1ee09e35a
5 changed files with 175 additions and 16 deletions

View File

@ -95,5 +95,13 @@ class ProductController(DatabaseController):
self.do(query, params)
def delete(self):
print("Doing work")
def delete(self, id: int):
params = [
id
]
query = """
DELETE FROM Products
WHERE id = ?
"""
self.do(query, params)

View File

@ -146,7 +146,7 @@ def update_product(id: int):
if product.sellerID != user_id:
flash("This product does not belong to you!", "error")
return redirect("/ownproducts")
return redirect("/products/ownproducts")
# Save new image file
file = request.files.get('image')
@ -168,6 +168,29 @@ def update_product(id: int):
return redirect(f"/products/{product.id}")
@blueprint.post('/delete/<int:id>')
def delete_product(id: int):
""" Processes a request to delete a product in place on the site """
# Ensure that the product belongs to the current user
user_id = session.get('user_id')
# User needs to be logged in as a seller to view this page
if not is_role("Seller"):
flash("You must be logged in as a seller to view this page!", "error")
return redirect("/")
db = ProductController()
product = db.read_id(id)
if product.sellerID != user_id:
flash("This product does not belong to you!", "error")
return redirect("/products/ownproducts")
db.delete(id)
flash("Product Removed!", "success")
return redirect("/products/ownproducts")
@blueprint.route('/ownproducts')
def display_own_products():
""" Display products owned by the currently logged in seller """