Automated Action 29d75cdf08 Implement Task Management API with FastAPI and SQLite
- Set up project structure and dependencies
- Create database models and schemas for tasks
- Implement CRUD operations for tasks
- Add API endpoints for task management
- Create Alembic migrations for the database
- Add health check endpoint
- Implement error handling
- Add documentation in README.md
2025-05-17 11:20:00 +00:00

32 lines
740 B
Python

from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.core.database import get_db
router = APIRouter()
@router.get("/", tags=["Health"])
async def health_check(db: Session = Depends(get_db)):
"""
Health check endpoint.
Verifies:
- API is running
- Database connection is working
"""
try:
# Test database connection
db.execute("SELECT 1")
return {
"status": "healthy",
"api": "up",
"database": "up",
}
except Exception as e:
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail=f"Service unhealthy: {str(e)}",
) from e