simpletodoapp-x9cyfn/api/routers/health_router.py
Automated Action 8e26cae20e Initial Todo app backend implementation with FastAPI and SQLite
- Created FastAPI application structure
- Added Todo model and CRUD operations
- Added database integration with SQLAlchemy
- Added migrations with Alembic
- Added health endpoint
- Added API documentation with Swagger UI and ReDoc
2025-05-16 00:35:49 +00:00

34 lines
893 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
import platform
import sys
from db.database import get_db
from api.schemas.health import HealthResponse
router = APIRouter()
@router.get("/health", response_model=HealthResponse)
def health_check(db: Session = Depends(get_db)):
"""
Health check endpoint that verifies the API is running correctly
and can connect to the database
"""
# Verify database connection
try:
# Just run a simple query to verify DB connection
db.execute("SELECT 1")
db_status = "healthy"
except Exception as e:
db_status = f"unhealthy: {str(e)}"
return HealthResponse(
status="healthy",
version="0.1.0",
details={
"database": db_status,
"python_version": sys.version,
"platform": platform.platform(),
}
)