47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import uuid
|
|
from typing import Optional, List
|
|
from decimal import Decimal
|
|
from pydantic import BaseModel, Field
|
|
|
|
from barker.schemas import to_camel
|
|
from barker.schemas.sale_category import SaleCategoryLink
|
|
|
|
|
|
class ProductLink(BaseModel):
|
|
id_: uuid.UUID = Field(...)
|
|
name: Optional[str]
|
|
enabled: Optional[bool]
|
|
|
|
class Config:
|
|
fields = {"id_": "id"}
|
|
|
|
|
|
class MenuCategoryLink(BaseModel): # Hack to prevent circular error
|
|
id_: uuid.UUID = Field(...)
|
|
products: Optional[List[ProductLink]]
|
|
|
|
class Config:
|
|
fields = {"id_": "id"}
|
|
|
|
|
|
class ProductIn(BaseModel):
|
|
name: str = Field(..., min_length=1)
|
|
units: str
|
|
menu_category: MenuCategoryLink = Field(...)
|
|
sale_category: SaleCategoryLink = Field(...)
|
|
price: Decimal # = Field(ge=0, multiple_of=0.01, default=0)
|
|
has_happy_hour: bool
|
|
is_not_available: bool
|
|
quantity: Decimal = Field(ge=0, multiple_of=0.01, default=0)
|
|
is_active: bool
|
|
sort_order: int
|
|
|
|
class Config:
|
|
fields = {"id_": "id"}
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|
|
|
|
|
|
class Product(ProductIn):
|
|
id_: uuid.UUID
|