recipe-inator/backend/app/schemas.py

80 lines
1.8 KiB
Python

from datetime import datetime
from typing import Literal
from pydantic import BaseModel, ConfigDict, Field
IngredientKind = Literal["item", "section_header"]
class IngredientIn(BaseModel):
kind: IngredientKind = "item"
quantity: str | None = None
unit: str | None = None
text: str
class IngredientOut(IngredientIn):
model_config = ConfigDict(from_attributes=True)
id: int
class StepIn(BaseModel):
text: str
class StepOut(StepIn):
model_config = ConfigDict(from_attributes=True)
id: int
class RecipeIn(BaseModel):
name: str = Field(min_length=1)
category: str | None = None
preptime: str | None = None
cooktime: str | None = None
baketime: str | None = None
cooltime: str | None = None
marinade_time: str | None = None
robot_time: str | None = None
servings: str | None = None
notes: str | None = None
kcal: str | None = None
kh: str | None = None
protein: str | None = None
fett: str | None = None
ingredients: list[IngredientIn] = Field(default_factory=list)
steps: list[StepIn] = Field(default_factory=list)
class RecipeSummary(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: int
name: str
slug: str
category: str | None
image_filename: str | None
class RecipeOut(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: int
name: str
slug: str
category: str | None
image_filename: str | None
preptime: str | None
cooktime: str | None
baketime: str | None
cooltime: str | None
marinade_time: str | None
robot_time: str | None
servings: str | None
notes: str | None
kcal: str | None
kh: str | None
protein: str | None
fett: str | None
created_at: datetime
updated_at: datetime
ingredients: list[IngredientOut]
steps: list[StepOut]