
This commit includes: - Project structure setup with FastAPI - Database models with SQLAlchemy (users, products, categories, orders) - SQLite database configuration - Alembic migration scripts - API endpoints for authentication, users, products, categories, and orders - JWT authentication - Comprehensive documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
71 lines
1.4 KiB
Python
71 lines
1.4 KiB
Python
from typing import Optional, List
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field
|
|
|
|
from app.models.order import OrderStatus
|
|
from app.schemas.product import Product
|
|
|
|
|
|
class OrderItemBase(BaseModel):
|
|
product_id: int
|
|
quantity: int = Field(1, gt=0)
|
|
price: Optional[float] = None # If not provided, will be taken from the product
|
|
|
|
|
|
class OrderItemCreate(OrderItemBase):
|
|
pass
|
|
|
|
|
|
class OrderItemUpdate(BaseModel):
|
|
quantity: Optional[int] = Field(None, gt=0)
|
|
|
|
|
|
class OrderItemInDBBase(OrderItemBase):
|
|
id: int
|
|
order_id: int
|
|
price: float # Price at time of purchase
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class OrderItem(OrderItemInDBBase):
|
|
product: Optional[Product] = None
|
|
|
|
|
|
class OrderItemInDB(OrderItemInDBBase):
|
|
pass
|
|
|
|
|
|
class OrderBase(BaseModel):
|
|
user_id: int
|
|
shipping_address: str
|
|
total_amount: Optional[float] = None # Will be calculated from items
|
|
|
|
|
|
class OrderCreate(OrderBase):
|
|
items: List[OrderItemCreate]
|
|
|
|
|
|
class OrderUpdate(BaseModel):
|
|
status: Optional[OrderStatus] = None
|
|
shipping_address: Optional[str] = None
|
|
|
|
|
|
class OrderInDBBase(OrderBase):
|
|
id: int
|
|
status: OrderStatus
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
total_amount: float
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class Order(OrderInDBBase):
|
|
items: List[OrderItem] = []
|
|
|
|
|
|
class OrderInDB(OrderInDBBase):
|
|
pass |