mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-28 21:15:26 -05:00
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:
@@ -1,2 +1,3 @@
|
||||
from .meal import *
|
||||
from .new_meal import *
|
||||
from .shopping_list import *
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
51
mealie/schema/meal_plan/new_meal.py
Normal file
51
mealie/schema/meal_plan/new_meal.py
Normal 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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user