"""Project health API endpoints. Provides endpoints for retrieving project health metrics and dashboard information. """ from typing import Optional from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.orm import Session from app.core.database import get_db from app.models import User from app.schemas.project_health import ( ProjectHealthWithDetails, ProjectHealthDashboardResponse, ) from app.services.health_service import HealthService from app.middleware.auth import get_current_user router = APIRouter(prefix="/api/projects/health", tags=["Project Health"]) @router.get("/dashboard", response_model=ProjectHealthDashboardResponse) async def get_health_dashboard( status_filter: Optional[str] = "active", db: Session = Depends(get_db), current_user: User = Depends(get_current_user), ): """ Get health dashboard for all projects. Returns aggregated health metrics and summary statistics for all projects matching the status filter. - **status_filter**: Filter projects by status (default: "active") Returns: - **projects**: List of project health details - **summary**: Aggregated summary statistics """ service = HealthService(db) return service.get_dashboard(status_filter=status_filter) @router.get("/{project_id}", response_model=ProjectHealthWithDetails) async def get_project_health( project_id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user), ): """ Get health information for a specific project. Returns detailed health metrics including risk level, schedule status, resource status, and task statistics. - **project_id**: UUID of the project Raises: - **404**: Project not found """ service = HealthService(db) result = service.get_project_health(project_id) if not result: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail="Project not found" ) return result