
- Set up project structure with FastAPI app - Implement SQLAlchemy models and async database connection - Create CRUD endpoints for items resource - Add health endpoint for monitoring - Configure Alembic for database migrations - Create comprehensive documentation generated with BackendIM... (backend.im)
26 lines
838 B
Python
26 lines
838 B
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
# Base Item schema with common attributes
|
|
class ItemBase(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=100, examples=["Item name"])
|
|
description: Optional[str] = Field(None, examples=["Item description"])
|
|
|
|
# Schema for creating a new item
|
|
class ItemCreate(ItemBase):
|
|
pass
|
|
|
|
# Schema for updating an existing item
|
|
class ItemUpdate(BaseModel):
|
|
name: Optional[str] = Field(None, min_length=1, max_length=100, examples=["Updated item name"])
|
|
description: Optional[str] = Field(None, examples=["Updated item description"])
|
|
|
|
# Schema for item responses
|
|
class ItemResponse(ItemBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True |