diff --git a/shopping/db.py b/shopping/db.py index 0aff51d..aa6ed52 100644 --- a/shopping/db.py +++ b/shopping/db.py @@ -201,28 +201,22 @@ async def request(conn, person: Person, ingredient: Optional[Ingredient] = None, return item -async def remove_request(conn, person: Person, meal: Optional[Meal] = None, ingredient: Optional[Ingredient] = None) -> None: - failed = True +async def remove_request(conn, person: Person, meal: Optional[Meal] = None, ingredient: Optional[Ingredient] = None) -> bool: if meal is not None: - # Ensure a record is removed async with conn.execute(''' DELETE FROM ShoppingListItem WHERE list_id IS NULL AND meal_id = ? ''', (meal.id,)) as cursor: - if cursor.rowcount > 0: - failed = False + return cursor.rowcount > 0 elif ingredient is not None: - # Ensure a record is removed async with conn.execute(''' DELETE FROM ShoppingListItem WHERE list_id IS NULL AND ingredient_id = ? AND person_id = ? ''', (ingredient.id, person.id)) as cursor: - if cursor.rowcount > 0: - failed = False + return cursor.rowcount > 0 - if failed: - raise ValueError('Must specify either a meal or an ingredient to remove') + raise ValueError('Must specify either a meal or an ingredient to remove') async def find_items_by_list_id(conn, list_id: Optional[int]) -> AsyncIterator[ShoppingListItem]: # Join Ingredient and Product to also load ingredient and product