Automated Action 12b80aca5b Implement and optimize Calculator API with FastAPI and SQLAlchemy
- Fixed Pydantic configuration using ConfigDict for latest Pydantic version
- Fixed import order in alembic/env.py for proper module imports
- Applied code formatting with Ruff
- Optimized database connection settings
- Ensured proper error handling for API endpoints

generated with BackendIM... (backend.im)
2025-05-13 23:22:34 +00:00

23 lines
630 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.db.session import get_db
router = APIRouter()
@router.get("/health")
def health_check(db: Session = Depends(get_db)):
"""
Health check endpoint for the API.
Returns status of the API and database connectivity.
"""
# Check database connection
try:
# Execute a simple query to verify database connectivity
db.execute("SELECT 1")
db_status = "healthy"
except Exception as e:
db_status = f"unhealthy: {str(e)}"
return {"status": "healthy", "database": db_status, "version": "1.0.0"}