feat(backend): rewrite mealplanner with simple api (#683)

* feat(backend):  new meal-planner feature

* feat(frontend):  new meal plan feature

* refactor(backend): ♻️ refactor base services classes and add mixins for crud

* feat(frontend):  add UI/API for mealplanner

* feat(backend):  add get_today and get_slice options for mealplanner

* test(backend):  add and update group mealplanner tests

* fix(backend): 🐛 Fix recipe_id column type for PG

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-09-12 11:05:09 -08:00
committed by GitHub
parent bdaf758712
commit b542583303
46 changed files with 869 additions and 255 deletions

View File

@@ -1,2 +1,3 @@
from .meal import *
from .new_meal import *
from .shopping_list import *

View File

@@ -3,9 +3,6 @@ from typing import Optional
from fastapi_camelcase import CamelModel
from pydantic import validator
from pydantic.utils import GetterDict
from mealie.db.models.mealplan import MealPlan
class MealIn(CamelModel):
@@ -54,18 +51,3 @@ class MealPlanOut(MealPlanIn):
class Config:
orm_mode = True
@classmethod
def getter_dict(_cls, name_orm: MealPlan):
try:
return {
**GetterDict(name_orm),
"group": name_orm.group.name,
"shopping_list": name_orm.shopping_list.id,
}
except Exception:
return {
**GetterDict(name_orm),
"group": name_orm.group.name,
"shopping_list": None,
}

View File

@@ -0,0 +1,51 @@
from datetime import date
from enum import Enum
from typing import Optional
from fastapi_camelcase import CamelModel
from pydantic import validator
from mealie.schema.recipe.recipe import RecipeSummary
class PlanEntryType(str, Enum):
breakfast = "breakfast"
lunch = "lunch"
dinner = "dinner"
snack = "snack"
class CreatePlanEntry(CamelModel):
date: date
entry_type: PlanEntryType = PlanEntryType.breakfast
title: str = ""
text: str = ""
recipe_id: Optional[int]
@validator("recipe_id", always=True)
@classmethod
def id_or_title(cls, value, values):
print(value, values)
if bool(value) is False and bool(values["title"]) is False:
raise ValueError(f"`recipe_id={value}` or `title={values['title']}` must be provided")
return value
class UpdatePlanEntry(CreatePlanEntry):
id: int
group_id: int
class SavePlanEntry(CreatePlanEntry):
group_id: int
class Config:
orm_mode = True
class ReadPlanEntry(UpdatePlanEntry):
recipe: Optional[RecipeSummary]
class Config:
orm_mode = True

View File

@@ -10,7 +10,7 @@ from mealie.db.models.users import User
from mealie.schema.group.group_preferences import ReadGroupPreferences
from mealie.schema.recipe import RecipeSummary
from ..meal_plan import MealPlanOut, ShoppingListOut
from ..meal_plan import ShoppingListOut
from ..recipe import CategoryBase
@@ -129,7 +129,6 @@ class UpdateGroup(GroupBase):
class GroupInDB(UpdateGroup):
users: Optional[list[UserOut]]
mealplans: Optional[list[MealPlanOut]]
shopping_lists: Optional[list[ShoppingListOut]]
preferences: Optional[ReadGroupPreferences] = None