restapi_key / app /crud /delete.py
FEATZAFF's picture
Upload 31 files
cce1e0e verified
Raw
History Blame Contribute Delete
985 Bytes
from sqlalchemy.orm import Session
from typing import Optional
from app.models.item import Item
def delete_item(db: Session, item_id: int) -> bool:
"""
Delete an item from the database.
Args:
db (Session): Database session
item_id (int): ID of the item to delete
Returns:
bool: True if the item was deleted, False if the item was not found
"""
item = db.query(Item).filter(Item.id == item_id).first()
if not item:
return False
db.delete(item)
db.commit()
return True
# TODO: Implement the delete_item function
# The function should:
# 1. Get the item with the given item_id from the database
# 2. If the item doesn't exist, return False
# 3. Delete the item from the database
# 4. Commit the changes
# 5. Return True to indicate successful deletion
# Delete the code below and implement your solution