rename grocery to product
This commit is contained in:
@@ -3,24 +3,24 @@ from typing import Optional, List
|
||||
from datetime import datetime
|
||||
|
||||
# Base schemas
|
||||
class GroceryBase(BaseModel):
|
||||
class ProductBase(BaseModel):
|
||||
name: str
|
||||
category: str
|
||||
organic: bool = False
|
||||
weight: Optional[float] = None
|
||||
weight_unit: str = "g"
|
||||
|
||||
class GroceryCreate(GroceryBase):
|
||||
class ProductCreate(ProductBase):
|
||||
pass
|
||||
|
||||
class GroceryUpdate(BaseModel):
|
||||
class ProductUpdate(BaseModel):
|
||||
name: Optional[str] = None
|
||||
category: Optional[str] = None
|
||||
organic: Optional[bool] = None
|
||||
weight: Optional[float] = None
|
||||
weight_unit: Optional[str] = None
|
||||
|
||||
class Grocery(GroceryBase):
|
||||
class Product(ProductBase):
|
||||
id: int
|
||||
created_at: datetime
|
||||
updated_at: Optional[datetime] = None
|
||||
@@ -51,12 +51,12 @@ class Shop(ShopBase):
|
||||
from_attributes = True
|
||||
|
||||
# Shopping Event schemas
|
||||
class GroceryInEvent(BaseModel):
|
||||
grocery_id: int
|
||||
class ProductInEvent(BaseModel):
|
||||
product_id: int
|
||||
amount: float = Field(..., gt=0)
|
||||
price: float = Field(..., ge=0) # Price at the time of this shopping event (allow free items)
|
||||
|
||||
class GroceryWithEventData(BaseModel):
|
||||
class ProductWithEventData(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
category: str
|
||||
@@ -76,21 +76,21 @@ class ShoppingEventBase(BaseModel):
|
||||
notes: Optional[str] = None
|
||||
|
||||
class ShoppingEventCreate(ShoppingEventBase):
|
||||
groceries: List[GroceryInEvent] = []
|
||||
products: List[ProductInEvent] = []
|
||||
|
||||
class ShoppingEventUpdate(BaseModel):
|
||||
shop_id: Optional[int] = None
|
||||
date: Optional[datetime] = None
|
||||
total_amount: Optional[float] = Field(None, ge=0)
|
||||
notes: Optional[str] = None
|
||||
groceries: Optional[List[GroceryInEvent]] = None
|
||||
products: Optional[List[ProductInEvent]] = None
|
||||
|
||||
class ShoppingEventResponse(ShoppingEventBase):
|
||||
id: int
|
||||
created_at: datetime
|
||||
updated_at: Optional[datetime] = None
|
||||
shop: Shop
|
||||
groceries: List[GroceryWithEventData] = []
|
||||
products: List[ProductWithEventData] = []
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
Reference in New Issue
Block a user