
- Implemented project structure with FastAPI framework - Set up SQLite database with SQLAlchemy ORM - Created Alembic for database migrations - Implemented Item model and CRUD operations - Added health check endpoint - Added error handling - Configured API documentation with Swagger UI generated with BackendIM... (backend.im)
36 lines
805 B
Python
36 lines
805 B
Python
from typing import Optional
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ItemBase(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=100)
|
|
description: Optional[str] = None
|
|
price: int = Field(..., gt=0) # Price in cents
|
|
is_active: bool = True
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
pass
|
|
|
|
|
|
class ItemUpdate(BaseModel):
|
|
name: Optional[str] = Field(None, min_length=1, max_length=100)
|
|
description: Optional[str] = None
|
|
price: Optional[int] = Field(None, gt=0)
|
|
is_active: Optional[bool] = None
|
|
|
|
|
|
class Item(ItemBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
from_attributes = True
|
|
|
|
|
|
class HealthCheck(BaseModel):
|
|
status: str
|
|
timestamp: datetime |