
- Set up project structure with FastAPI framework - Implement database models using SQLAlchemy - Create Alembic migrations for database schema - Build CRUD endpoints for Items resource - Add health check endpoint - Include API documentation with Swagger and ReDoc - Update README with project documentation
40 lines
807 B
Python
40 lines
807 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
|
|
class ItemBase(BaseModel):
|
|
name: str
|
|
description: Optional[str] = None
|
|
price: int = Field(description="Price in cents")
|
|
is_active: bool = True
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
pass
|
|
|
|
|
|
class ItemUpdate(BaseModel):
|
|
name: Optional[str] = None
|
|
description: Optional[str] = None
|
|
price: Optional[int] = None
|
|
is_active: Optional[bool] = None
|
|
|
|
|
|
class ItemInDBBase(ItemBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class Item(ItemInDBBase):
|
|
"""Response model for API"""
|
|
pass
|
|
|
|
|
|
class ItemInDB(ItemInDBBase):
|
|
"""Internal model with potential sensitive data"""
|
|
pass |