mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-01-03 07:31:22 -05:00
support empty meal-plans
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user