
- Set up FastAPI project structure - Configure SQLAlchemy with SQLite - Create Todo model and schemas - Implement CRUD operations - Add API endpoints for Todo management - Configure Alembic for database migrations - Add health check endpoint - Add comprehensive documentation
26 lines
747 B
Python
26 lines
747 B
Python
from fastapi import APIRouter, Depends, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db.session import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", status_code=status.HTTP_200_OK)
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint to verify API is running and database is accessible
|
|
"""
|
|
try:
|
|
# Execute a simple query to check if database is accessible
|
|
db.execute("SELECT 1")
|
|
return {
|
|
"status": "healthy",
|
|
"message": "API is running and database is accessible",
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
"status": "unhealthy",
|
|
"message": f"API is running but database is not accessible: {str(e)}",
|
|
}
|