Automated Action b8143c43e4 Implement ecommerce authentication and inventory API
- Set up project structure and FastAPI application
- Create database models for users, products, and inventory
- Configure SQLAlchemy and Alembic for database management
- Implement JWT authentication
- Create API endpoints for user, product, and inventory management
- Add admin-only routes and authorization middleware
- Add health check endpoint
- Update README with documentation
- Lint and fix code issues
2025-06-08 21:40:55 +00:00

82 lines
1.8 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
# Category schemas
class CategoryBase(BaseModel):
"""Base category schema."""
name: str
description: Optional[str] = None
class CategoryCreate(CategoryBase):
"""Category creation schema."""
pass
class CategoryUpdate(BaseModel):
"""Category update schema."""
name: Optional[str] = None
description: Optional[str] = None
class Category(CategoryBase):
"""Category schema to return to client."""
id: str
created_at: datetime
updated_at: datetime
class Config:
"""Configuration for the schema."""
from_attributes = True
# Product schemas
class ProductBase(BaseModel):
"""Base product schema."""
name: str
description: Optional[str] = None
price: float = Field(..., gt=0)
sku: str
is_active: bool = True
category_id: Optional[str] = None
class ProductCreate(ProductBase):
"""Product creation schema."""
pass
class ProductUpdate(BaseModel):
"""Product update schema."""
name: Optional[str] = None
description: Optional[str] = None
price: Optional[float] = Field(None, gt=0)
sku: Optional[str] = None
is_active: Optional[bool] = None
category_id: Optional[str] = None
class ProductWithCategory(ProductBase):
"""Product schema with category to return to client."""
id: str
created_at: datetime
updated_at: datetime
category: Optional[Category] = None
class Config:
"""Configuration for the schema."""
from_attributes = True
class Product(ProductBase):
"""Product schema to return to client."""
id: str
created_at: datetime
updated_at: datetime
class Config:
"""Configuration for the schema."""
from_attributes = True