API Endpoint

This commit is contained in:
hay-kot 2021-02-18 19:29:29 -09:00
commit 69c9149e77

View file

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