
Create a complete e-commerce application with the following features: - User authentication and authorization - Product and category management - Shopping cart functionality - Order processing - Database migrations with Alembic - Comprehensive documentation
57 lines
1.2 KiB
Python
57 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
|
|
|
|
class Config:
|
|
orm_mode = 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
|
|
|
|
class Config:
|
|
orm_mode = True |