From fba3ed68fa6aa457d0058517525aa6243d858a22 Mon Sep 17 00:00:00 2001 From: Hayden Date: Tue, 5 Jan 2021 17:36:53 -0900 Subject: [PATCH] support empty meal-plans --- .../src/components/MealPlan/MealPlanner.vue | 3 +- frontend/src/components/MealPlan/NewMeal.vue | 2 +- mealie/routes/meal_routes.py | 17 ++++++----- mealie/services/meal_services.py | 29 ++++++++++++------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/MealPlan/MealPlanner.vue b/frontend/src/components/MealPlan/MealPlanner.vue index 5a3ff07f..fca4f79a 100644 --- a/frontend/src/components/MealPlan/MealPlanner.vue +++ b/frontend/src/components/MealPlan/MealPlanner.vue @@ -33,7 +33,7 @@ :key="generateKey(meal.slug, index)" > { if (element.uid === id) { - console.log(element); this.editMealPlan = element; } }); diff --git a/frontend/src/components/MealPlan/NewMeal.vue b/frontend/src/components/MealPlan/NewMeal.vue index fe9f574e..800412fc 100644 --- a/frontend/src/components/MealPlan/NewMeal.vue +++ b/frontend/src/components/MealPlan/NewMeal.vue @@ -107,7 +107,7 @@ export default { this.meals = []; for (let i = 0; i < this.dateDif; i++) { this.meals.push({ - slug: "", + slug: "empty", date: this.getDate(i), dateText: this.getDayText(i), }); diff --git a/mealie/routes/meal_routes.py b/mealie/routes/meal_routes.py index ebf871c1..f9ace57d 100644 --- a/mealie/routes/meal_routes.py +++ b/mealie/routes/meal_routes.py @@ -17,15 +17,16 @@ async def get_all_meals(): @router.post("/api/meal-plan/create/", tags=["Meal Plan"]) async def set_meal_plan(data: MealPlan): """ Creates Mealplan from Frontend Data""" + data.process_meals() + data.save_to_db() + + # try: - try: - data.process_meals() - data.save_to_db() - except: - raise HTTPException( - status_code=404, - detail=SnackResponse.error("Unable to Create Mealplan See Log"), - ) + # except: + # raise HTTPException( + # status_code=404, + # detail=SnackResponse.error("Unable to Create Mealplan See Log"), + # ) return SnackResponse.success("Mealplan Created") diff --git a/mealie/services/meal_services.py b/mealie/services/meal_services.py index b4dd7b81..336b1528 100644 --- a/mealie/services/meal_services.py +++ b/mealie/services/meal_services.py @@ -23,9 +23,9 @@ WEEKDAYS = [ class Meal(BaseModel): - slug: str + slug: Optional[str] name: Optional[str] - date: Optional[date] + date: date dateText: str image: Optional[str] description: Optional[str] @@ -57,16 +57,23 @@ class MealPlan(BaseModel): def process_meals(self): meals = [] for x, meal in enumerate(self.meals): - recipe = Recipe.get_by_slug(meal.slug) - meal_data = { - "slug": recipe.slug, - "name": recipe.name, - "date": self.startDate + timedelta(days=x), - "dateText": meal.dateText, - "image": recipe.image, - "description": recipe.description, - } + try: + recipe = Recipe.get_by_slug(meal.slug) + + meal_data = { + "slug": recipe.slug, + "name": recipe.name, + "date": self.startDate + timedelta(days=x), + "dateText": meal.dateText, + "image": recipe.image, + "description": recipe.description, + } + except: + meal_data = { + "date": self.startDate + timedelta(days=x), + "dateText": meal.dateText, + } meals.append(Meal(**meal_data))