2021-08-31 14:39:29 -08:00
|
|
|
from fastapi_camelcase import CamelModel
|
2022-01-13 13:06:52 -09:00
|
|
|
from pydantic import UUID4, validator
|
2021-08-31 14:39:29 -08:00
|
|
|
from slugify import slugify
|
|
|
|
|
2021-08-31 18:51:34 -08:00
|
|
|
from ..recipe.recipe_category import CategoryBase, RecipeCategoryResponse
|
2021-08-31 14:39:29 -08:00
|
|
|
|
|
|
|
|
|
|
|
class CreateCookBook(CamelModel):
|
|
|
|
name: str
|
2021-08-31 18:51:34 -08:00
|
|
|
description: str = ""
|
2021-08-31 14:39:29 -08:00
|
|
|
slug: str = None
|
|
|
|
position: int = 1
|
|
|
|
categories: list[CategoryBase] = []
|
|
|
|
|
|
|
|
@validator("slug", always=True, pre=True)
|
|
|
|
def validate_slug(slug: str, values):
|
|
|
|
name: str = values["name"]
|
|
|
|
calc_slug: str = slugify(name)
|
|
|
|
|
|
|
|
if slug != calc_slug:
|
|
|
|
slug = calc_slug
|
|
|
|
|
|
|
|
return slug
|
|
|
|
|
|
|
|
|
2022-01-13 13:06:52 -09:00
|
|
|
class SaveCookBook(CreateCookBook):
|
|
|
|
group_id: UUID4
|
2021-08-31 14:39:29 -08:00
|
|
|
|
|
|
|
|
2022-01-13 13:06:52 -09:00
|
|
|
class UpdateCookBook(SaveCookBook):
|
2022-02-20 14:17:51 -09:00
|
|
|
id: UUID4
|
2021-08-31 14:39:29 -08:00
|
|
|
|
|
|
|
|
|
|
|
class ReadCookBook(UpdateCookBook):
|
2022-01-13 13:06:52 -09:00
|
|
|
group_id: UUID4
|
2021-08-31 14:39:29 -08:00
|
|
|
categories: list[CategoryBase] = []
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
orm_mode = True
|
2021-08-31 18:51:34 -08:00
|
|
|
|
|
|
|
|
|
|
|
class RecipeCookBook(ReadCookBook):
|
2022-01-13 13:06:52 -09:00
|
|
|
group_id: UUID4
|
2021-08-31 18:51:34 -08:00
|
|
|
categories: list[RecipeCategoryResponse]
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
orm_mode = True
|