
Create a full-featured task management API with the following components: - RESTful CRUD operations for tasks - Task status and priority management - SQLite database with SQLAlchemy ORM - Alembic migrations - Health check endpoint - Comprehensive API documentation
39 lines
759 B
Python
39 lines
759 B
Python
"""
|
|
Health check endpoint.
|
|
"""
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db.session import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class HealthCheck(BaseModel):
|
|
"""
|
|
Health check response schema.
|
|
"""
|
|
status: str
|
|
database: bool
|
|
|
|
|
|
@router.get("", response_model=HealthCheck)
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint.
|
|
|
|
Returns:
|
|
HealthCheck: Health status including database connectivity.
|
|
"""
|
|
# Check if database is accessible
|
|
try:
|
|
db.execute("SELECT 1")
|
|
db_status = True
|
|
except Exception:
|
|
db_status = False
|
|
|
|
return {
|
|
"status": "healthy",
|
|
"database": db_status
|
|
} |