Allowed for null products, move ingredient spreading server-side #1

Merged
jacob merged 7 commits from nullproducts into master 2025-07-28 23:23:10 +00:00
Showing only changes of commit dca63bd51a - Show all commits

View file

@ -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