Automated Action 3efcd88ffa Create Calculator API with FastAPI and SQLAlchemy
- Setup FastAPI project structure
- Add database models for calculations
- Create API endpoints for basic math operations
- Add health endpoint
- Configure SQLite and Alembic for database management
- Update README with usage instructions

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

25 lines
662 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"
}