
- Implement Todo database model with SQLAlchemy - Set up Alembic for database migrations - Create CRUD operations for Todo items - Implement RESTful API endpoints - Add health check endpoint - Include comprehensive README with usage instructions
37 lines
814 B
Python
37 lines
814 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import text
|
|
from pydantic import BaseModel
|
|
|
|
from app.database import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
"""Response model for health check endpoint."""
|
|
|
|
status: str
|
|
version: str
|
|
database: str
|
|
|
|
|
|
@router.get("/health", response_model=HealthResponse)
|
|
def health_check(db: Session = Depends(get_db)) -> HealthResponse:
|
|
"""
|
|
Health check endpoint to verify API and database status.
|
|
|
|
Args:
|
|
db: Database session
|
|
|
|
Returns:
|
|
Health status information
|
|
"""
|
|
# Test database connectivity
|
|
db.execute(text("SELECT 1"))
|
|
|
|
return HealthResponse(
|
|
status="healthy",
|
|
version="0.1.0",
|
|
database="connected"
|
|
) |