Include shops from upcoming meals in shopping list
This commit is contained in:
parent
3d2d681a7d
commit
a0c2b88a55
1 changed files with 8 additions and 8 deletions
14
main.py
14
main.py
|
|
@ -259,17 +259,17 @@ class CurrentShoppingList(BaseModel):
|
|||
|
||||
@app.get("/api/shopping/current")
|
||||
async def get_current_shopping_list(conn: sqlite3.Connection = Depends(get_db)) -> CurrentShoppingList:
|
||||
overlapping = []
|
||||
current_requests = [r async for r in shopping.get_current_requests(conn)]
|
||||
|
||||
for request in current_requests:
|
||||
if request.meal_id:
|
||||
overlapping.extend([r async for r in shopping.get_shopping_list_with_meal(conn, request.meal_id)])
|
||||
requested_meals = [r.meal_id for r in current_requests if r.meal_id]
|
||||
upcoming_meals = [m.id async for m in meals.find_upcoming_meals_by_date_range(conn, datetime.datetime.now().astimezone(), datetime.datetime.now().astimezone() + datetime.timedelta(days=14))]
|
||||
|
||||
seen = set()
|
||||
overlapping = [o for o in overlapping if o.id not in seen and not seen.add(o.id)]
|
||||
overlapping = {}
|
||||
for meal_id in set(requested_meals + upcoming_meals):
|
||||
async for r in shopping.get_shopping_list_with_meal(conn, meal_id):
|
||||
overlapping[r.id] = r
|
||||
|
||||
return CurrentShoppingList(requests=current_requests, overlapping_previous_shops=overlapping)
|
||||
return CurrentShoppingList(requests=current_requests, overlapping_previous_shops=list(overlapping.values()))
|
||||
|
||||
@app.get("/api/shopping/{list_id}")
|
||||
async def get_shopping_list(list_id: int, conn: sqlite3.Connection = Depends(get_db)) -> shopping.ShoppingList:
|
||||
|
|
|
|||
Loading…
Reference in a new issue