Spaces:
Sleeping
Sleeping
File size: 985 Bytes
cce1e0e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 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
|