Files
mealie/mealie/schema/meal_plan/new_meal.py
Michael Genson 5f7ac92c96 feat: timeline event for mealplans (#2050)
* added related user to mealplans

* made timeline event message actually optional

* added task to create events for mealplan recipes

* replaced fk constraint ops with bulk ops

* fixed event creation and adjusted query range

* indentation is hard

* added missing recipe id query filter

* added tests
2023-02-11 10:08:53 -09:00

63 lines
1.3 KiB
Python

from datetime import date
from enum import Enum
from uuid import UUID
from pydantic import validator
from mealie.schema._mealie import MealieModel
from mealie.schema.recipe.recipe import RecipeSummary
from mealie.schema.response.pagination import PaginationBase
class PlanEntryType(str, Enum):
breakfast = "breakfast"
lunch = "lunch"
dinner = "dinner"
side = "side"
class CreateRandomEntry(MealieModel):
date: date
entry_type: PlanEntryType = PlanEntryType.dinner
class CreatePlanEntry(MealieModel):
date: date
entry_type: PlanEntryType = PlanEntryType.breakfast
title: str = ""
text: str = ""
recipe_id: UUID | None
@validator("recipe_id", always=True)
@classmethod
def id_or_title(cls, 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: UUID
user_id: UUID | None
class SavePlanEntry(CreatePlanEntry):
group_id: UUID
user_id: UUID | None
class Config:
orm_mode = True
class ReadPlanEntry(UpdatePlanEntry):
recipe: RecipeSummary | None
class Config:
orm_mode = True
class PlanEntryPagination(PaginationBase):
items: list[ReadPlanEntry]