
- Update Pydantic models to use model_config instead of Config class for v2 compatibility - Fix CORS settings to allow all origins in development mode - Fix circular imports in auth.py - Remove unused imports
59 lines
1.2 KiB
Python
59 lines
1.2 KiB
Python
from typing import Optional
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# Shared properties
|
|
class ProductBase(BaseModel):
|
|
name: str
|
|
description: Optional[str] = None
|
|
price: float = Field(..., gt=0)
|
|
stock: int = Field(..., ge=0)
|
|
is_active: bool = True
|
|
category_id: str
|
|
image_url: Optional[str] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class ProductCreate(ProductBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class ProductUpdate(ProductBase):
|
|
name: Optional[str] = None
|
|
description: Optional[str] = None
|
|
price: Optional[float] = None
|
|
stock: Optional[int] = None
|
|
is_active: Optional[bool] = None
|
|
category_id: Optional[str] = None
|
|
image_url: Optional[str] = None
|
|
|
|
|
|
class ProductInDBBase(ProductBase):
|
|
id: str
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
model_config = {
|
|
"from_attributes": True
|
|
}
|
|
|
|
|
|
# Additional properties to return via API
|
|
class Product(ProductInDBBase):
|
|
pass
|
|
|
|
|
|
# Product with minimal data for list views
|
|
class ProductList(BaseModel):
|
|
id: str
|
|
name: str
|
|
price: float
|
|
image_url: Optional[str] = None
|
|
category_id: str
|
|
is_active: bool
|
|
|
|
model_config = {
|
|
"from_attributes": True
|
|
} |