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
16
main.py
16
main.py
|
|
@ -259,17 +259,17 @@ class CurrentShoppingList(BaseModel):
|
||||||
|
|
||||||
@app.get("/api/shopping/current")
|
@app.get("/api/shopping/current")
|
||||||
async def get_current_shopping_list(conn: sqlite3.Connection = Depends(get_db)) -> CurrentShoppingList:
|
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)]
|
current_requests = [r async for r in shopping.get_current_requests(conn)]
|
||||||
|
|
||||||
|
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))]
|
||||||
|
|
||||||
for request in current_requests:
|
overlapping = {}
|
||||||
if request.meal_id:
|
for meal_id in set(requested_meals + upcoming_meals):
|
||||||
overlapping.extend([r async for r in shopping.get_shopping_list_with_meal(conn, request.meal_id)])
|
async for r in shopping.get_shopping_list_with_meal(conn, meal_id):
|
||||||
|
overlapping[r.id] = r
|
||||||
|
|
||||||
seen = set()
|
return CurrentShoppingList(requests=current_requests, overlapping_previous_shops=list(overlapping.values()))
|
||||||
overlapping = [o for o in overlapping if o.id not in seen and not seen.add(o.id)]
|
|
||||||
|
|
||||||
return CurrentShoppingList(requests=current_requests, overlapping_previous_shops=overlapping)
|
|
||||||
|
|
||||||
@app.get("/api/shopping/{list_id}")
|
@app.get("/api/shopping/{list_id}")
|
||||||
async def get_shopping_list(list_id: int, conn: sqlite3.Connection = Depends(get_db)) -> shopping.ShoppingList:
|
async def get_shopping_list(list_id: int, conn: sqlite3.Connection = Depends(get_db)) -> shopping.ShoppingList:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue