Backend:
- OrderItemInput accepts option objects {id,name,price_delta} instead of int IDs
- extra_cost from selected options added to unit_price snapshot
- GET /api/products/?all=true for manager (includes unavailable)
- PUT /api/products/{id} now replaces options, ingredients, preference_sets
- POST /api/products/{id}/image — persistent image upload to /app/data/product_images
- New models: ProductPreferenceSet, ProductPreferenceChoice, TableGroup
- tables: group_id FK, hard delete (?hard=true), batch create POST /api/tables/batch
- GET /api/tables/groups + POST/PUT/DELETE groups endpoints
- POST /api/auth/me endpoint for token rehydration
- Auto-migration on startup for new columns
PWA:
- AuthRehydrator: fetches /auth/me on load so isMyOrder works after page reload
- 401 response force-logs out (covers blocked waiters)
- ItemOptionsModal: uses extra_cost correctly, shows preferences as radio buttons
Manager:
- ProductsPage: shows unavailable products greyed out, category color picker + reorder,
full option/ingredient/preference editing, image upload
- TablesPage: table groups, auto-increment, deactivate vs hard delete, batch add
136 lines
3.5 KiB
Python
136 lines
3.5 KiB
Python
from pydantic import BaseModel
|
|
from typing import Optional, List
|
|
|
|
|
|
class CategoryCreate(BaseModel):
|
|
name: str
|
|
color: Optional[str] = None
|
|
sort_order: int = 0
|
|
|
|
|
|
class CategoryUpdate(BaseModel):
|
|
name: Optional[str] = None
|
|
color: Optional[str] = None
|
|
sort_order: Optional[int] = None
|
|
|
|
|
|
class CategoryOut(BaseModel):
|
|
id: int
|
|
name: str
|
|
color: Optional[str] = None
|
|
sort_order: int = 0
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class CategoryReorderItem(BaseModel):
|
|
id: int
|
|
sort_order: int
|
|
|
|
|
|
# ── Options ──────────────────────────────────────────────────────────────────
|
|
|
|
class ProductOptionBase(BaseModel):
|
|
name: str
|
|
extra_cost: float = 0.0
|
|
|
|
|
|
class ProductOptionCreate(ProductOptionBase):
|
|
pass
|
|
|
|
|
|
class ProductOptionOut(ProductOptionBase):
|
|
id: int
|
|
product_id: int
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# ── Ingredients ───────────────────────────────────────────────────────────────
|
|
|
|
class ProductIngredientBase(BaseModel):
|
|
name: str
|
|
extra_cost: float = 0.0
|
|
|
|
|
|
class ProductIngredientCreate(ProductIngredientBase):
|
|
pass
|
|
|
|
|
|
class ProductIngredientOut(ProductIngredientBase):
|
|
id: int
|
|
product_id: int
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# ── Preferences ───────────────────────────────────────────────────────────────
|
|
|
|
class PreferenceChoiceBase(BaseModel):
|
|
name: str
|
|
extra_cost: float = 0.0
|
|
|
|
|
|
class PreferenceChoiceCreate(PreferenceChoiceBase):
|
|
pass
|
|
|
|
|
|
class PreferenceChoiceOut(PreferenceChoiceBase):
|
|
id: int
|
|
set_id: int
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class PreferenceSetBase(BaseModel):
|
|
name: str
|
|
|
|
|
|
class PreferenceSetCreate(PreferenceSetBase):
|
|
choices: List[PreferenceChoiceCreate] = []
|
|
|
|
|
|
class PreferenceSetOut(PreferenceSetBase):
|
|
id: int
|
|
product_id: int
|
|
choices: List[PreferenceChoiceOut] = []
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# ── Products ──────────────────────────────────────────────────────────────────
|
|
|
|
class ProductBase(BaseModel):
|
|
name: str
|
|
category_id: Optional[int] = None
|
|
base_price: float
|
|
is_available: bool = True
|
|
printer_zone_id: Optional[int] = None
|
|
|
|
|
|
class ProductCreate(ProductBase):
|
|
options: List[ProductOptionCreate] = []
|
|
ingredients: List[ProductIngredientCreate] = []
|
|
preference_sets: List[PreferenceSetCreate] = []
|
|
|
|
|
|
class ProductUpdate(BaseModel):
|
|
name: Optional[str] = None
|
|
category_id: Optional[int] = None
|
|
base_price: Optional[float] = None
|
|
is_available: Optional[bool] = None
|
|
printer_zone_id: Optional[int] = None
|
|
options: Optional[List[ProductOptionCreate]] = None
|
|
ingredients: Optional[List[ProductIngredientCreate]] = None
|
|
preference_sets: Optional[List[PreferenceSetCreate]] = None
|
|
|
|
|
|
class ProductOut(ProductBase):
|
|
id: int
|
|
options: List[ProductOptionOut] = []
|
|
ingredients: List[ProductIngredientOut] = []
|
|
preference_sets: List[PreferenceSetOut] = []
|
|
image_url: Optional[str] = None
|
|
|
|
model_config = {"from_attributes": True}
|