
- Create project structure and configuration files - Set up database models and schemas for ToDo items - Implement CRUD operations for ToDo management - Create API endpoints for ToDo operations - Add health check endpoint - Set up Alembic for database migrations - Add comprehensive README documentation
33 lines
821 B
Python
33 lines
821 B
Python
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import text
|
|
|
|
from app.db.session import get_db
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str
|
|
database_connected: bool
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", response_model=HealthResponse)
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint to verify API and database status.
|
|
"""
|
|
# Check database connection
|
|
try:
|
|
# Execute a simple query to verify database connection
|
|
db.execute(text("SELECT 1"))
|
|
database_connected = True
|
|
except Exception:
|
|
database_connected = False
|
|
|
|
return HealthResponse(
|
|
status="OK" if database_connected else "ERROR",
|
|
database_connected=database_connected,
|
|
) |