support empty meal-plans

This commit is contained in:
Hayden 2021-01-05 17:36:53 -09:00
parent e662e43288
commit fba3ed68fa
4 changed files with 29 additions and 22 deletions

View file

@ -33,7 +33,7 @@
:key="generateKey(meal.slug, index)"
>
<v-img
class="rounded-lg"
class="rounded-lg info"
:src="getImage(meal.image)"
height="80"
width="80"
@ -105,7 +105,6 @@ export default {
editPlan(id) {
this.plannedMeals.forEach((element) => {
if (element.uid === id) {
console.log(element);
this.editMealPlan = element;
}
});

View file

@ -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),
});

View file

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

View file

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