mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
API Endpoint
This commit is contained in:
parent
a56d4f6d11
commit
69c9149e77
1 changed files with 16 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
from typing import List
|
||||
|
||||
from db.database import db
|
||||
from db.db_setup import generate_session
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from services.meal_services import MealPlan
|
||||
|
@ -16,6 +17,21 @@ def get_all_meals(session: Session = Depends(generate_session)):
|
|||
return MealPlan.get_all(session)
|
||||
|
||||
|
||||
@router.get("/shopping-list/{id}")
|
||||
def get_shopping_list(id: str, session: Session = Depends(generate_session)):
|
||||
|
||||
#! Refactor into Single Database Call
|
||||
mealplan = db.meals.get(session, id)
|
||||
slugs = [x.get("slug") for x in mealplan.get("meals")]
|
||||
recipes = [db.recipes.get(session, x) for x in slugs]
|
||||
ingredients = [
|
||||
{"name": x.get("name"), "recipeIngredient": x.get("recipeIngredient")}
|
||||
for x in recipes
|
||||
]
|
||||
|
||||
return {"ingredients": ingredients}
|
||||
|
||||
|
||||
@router.post("/create")
|
||||
def set_meal_plan(data: MealPlan, session: Session = Depends(generate_session)):
|
||||
""" Creates a meal plan database entry """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue