Allowed for null products, move ingredient spreading server-side #1
1 changed files with 4 additions and 10 deletions
|
|
@ -201,28 +201,22 @@ async def request(conn, person: Person, ingredient: Optional[Ingredient] = None,
|
||||||
|
|
||||||
return item
|
return item
|
||||||
|
|
||||||
async def remove_request(conn, person: Person, meal: Optional[Meal] = None, ingredient: Optional[Ingredient] = None) -> None:
|
async def remove_request(conn, person: Person, meal: Optional[Meal] = None, ingredient: Optional[Ingredient] = None) -> bool:
|
||||||
failed = True
|
|
||||||
if meal is not None:
|
if meal is not None:
|
||||||
# Ensure a record is removed
|
|
||||||
async with conn.execute('''
|
async with conn.execute('''
|
||||||
DELETE FROM ShoppingListItem
|
DELETE FROM ShoppingListItem
|
||||||
WHERE list_id IS NULL AND meal_id = ?
|
WHERE list_id IS NULL AND meal_id = ?
|
||||||
''', (meal.id,)) as cursor:
|
''', (meal.id,)) as cursor:
|
||||||
if cursor.rowcount > 0:
|
return cursor.rowcount > 0
|
||||||
failed = False
|
|
||||||
|
|
||||||
elif ingredient is not None:
|
elif ingredient is not None:
|
||||||
# Ensure a record is removed
|
|
||||||
async with conn.execute('''
|
async with conn.execute('''
|
||||||
DELETE FROM ShoppingListItem
|
DELETE FROM ShoppingListItem
|
||||||
WHERE list_id IS NULL AND ingredient_id = ? AND person_id = ?
|
WHERE list_id IS NULL AND ingredient_id = ? AND person_id = ?
|
||||||
''', (ingredient.id, person.id)) as cursor:
|
''', (ingredient.id, person.id)) as cursor:
|
||||||
if cursor.rowcount > 0:
|
return cursor.rowcount > 0
|
||||||
failed = False
|
|
||||||
|
|
||||||
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]:
|
async def find_items_by_list_id(conn, list_id: Optional[int]) -> AsyncIterator[ShoppingListItem]:
|
||||||
# Join Ingredient and Product to also load ingredient and product
|
# Join Ingredient and Product to also load ingredient and product
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue