feature/mealplanner-rewrite (#417)

* multiple recipes per day

* fix update

* meal-planner rewrite

* disable meal-tests

* spacing

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-05-22 21:04:19 -08:00
committed by GitHub
parent 4b3fc45c1c
commit ef87f2231d
42 changed files with 1502 additions and 491 deletions

View File

@@ -1,51 +1,70 @@
from datetime import date
from typing import List, Optional
from typing import Optional
from mealie.db.models.mealplan import MealPlanModel
from pydantic import BaseModel, validator
from fastapi_camelcase import CamelModel
from mealie.db.models.mealplan import MealPlan
from pydantic import validator
from pydantic.utils import GetterDict
class MealIn(BaseModel):
name: Optional[str]
class MealIn(CamelModel):
slug: Optional[str]
date: Optional[date]
class MealOut(MealIn):
image: Optional[str]
name: Optional[str]
description: Optional[str]
class Config:
orm_mode = True
class MealPlanIn(BaseModel):
group: str
startDate: date
endDate: date
meals: List[MealIn]
class MealDayIn(CamelModel):
date: Optional[date]
meals: list[MealIn]
@validator("endDate")
def endDate_after_startDate(v, values, config, field):
if "startDate" in values and v < values["startDate"]:
class Config:
orm_mode = True
class MealDayOut(MealDayIn):
id: int
class Config:
orm_mode = True
class MealPlanIn(CamelModel):
group: str
start_date: date
end_date: date
plan_days: list[MealDayIn]
@validator("end_date")
def end_date_after_start_date(v, values, config, field):
if "start_date" in values and v < values["start_date"]:
raise ValueError("EndDate should be greater than StartDate")
return v
class MealPlanProcessed(MealPlanIn):
meals: list[MealOut]
class Config:
orm_mode = True
class MealPlanInDB(MealPlanProcessed):
uid: str
class MealPlanOut(MealPlanIn):
uid: int
shopping_list: Optional[int]
class Config:
orm_mode = True
@classmethod
def getter_dict(_cls, name_orm: MealPlanModel):
return {
**GetterDict(name_orm),
"group": name_orm.group.name,
}
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,35 @@
from typing import Optional
from fastapi_camelcase import CamelModel
from mealie.db.models.shopping_list import ShoppingList
from pydantic.utils import GetterDict
class ListItem(CamelModel):
title: Optional[str]
text: str = ""
quantity: int = 1
checked: bool = False
class Config:
orm_mode = True
class ShoppingListIn(CamelModel):
name: str
group: Optional[str]
items: list[ListItem]
class ShoppingListOut(ShoppingListIn):
id: int
class Config:
orm_mode = True
@classmethod
def getter_dict(cls, ormModel: ShoppingList):
return {
**GetterDict(ormModel),
"group": ormModel.group.name,
}

View File

@@ -5,7 +5,8 @@ from mealie.core.config import settings
from mealie.db.models.group import Group
from mealie.db.models.users import User
from mealie.schema.category import CategoryBase
from mealie.schema.meal import MealPlanInDB
from mealie.schema.meal import MealPlanOut
from mealie.schema.shopping_list import ShoppingListOut
from pydantic.types import constr
from pydantic.utils import GetterDict
@@ -105,7 +106,8 @@ class UpdateGroup(GroupBase):
class GroupInDB(UpdateGroup):
users: Optional[list[UserOut]]
mealplans: Optional[list[MealPlanInDB]]
mealplans: Optional[list[MealPlanOut]]
shopping_lists: Optional[list[ShoppingListOut]]
class Config:
orm_mode = True