
- Setup project structure and FastAPI application - Create SQLAlchemy models for users, products, carts, and orders - Implement Alembic migrations - Add CRUD operations and endpoints for all resources - Setup authentication with JWT - Add role-based access control - Update documentation
45 lines
890 B
Python
45 lines
890 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# Shared properties
|
|
class ProductBase(BaseModel):
|
|
name: Optional[str] = None
|
|
description: Optional[str] = None
|
|
price: Optional[float] = None
|
|
stock: Optional[int] = None
|
|
image_url: Optional[str] = None
|
|
|
|
|
|
# Properties to receive on product creation
|
|
class ProductCreate(ProductBase):
|
|
name: str
|
|
price: float = Field(..., gt=0)
|
|
stock: int = Field(..., ge=0)
|
|
|
|
|
|
# Properties to receive on product update
|
|
class ProductUpdate(ProductBase):
|
|
pass
|
|
|
|
|
|
class ProductInDBBase(ProductBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Additional properties to return via API
|
|
class Product(ProductInDBBase):
|
|
pass
|
|
|
|
|
|
# Additional properties stored in DB
|
|
class ProductInDB(ProductInDBBase):
|
|
pass
|