abfd07331e
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""Dashboard API routes."""
|
|
|
|
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database import get_db
|
|
from app.services.analytics_service import AnalyticsService
|
|
|
|
router = APIRouter(prefix="/api/dashboard", tags=["dashboard"])
|
|
|
|
|
|
@router.get("/stats")
|
|
async def dashboard_stats(
|
|
project: Optional[str] = Query(None),
|
|
hours: int = Query(24, ge=1, le=720),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
"""Get overview statistics for the dashboard."""
|
|
service = AnalyticsService(db)
|
|
return await service.get_dashboard_stats(project=project, hours=hours)
|
|
|
|
|
|
@router.get("/timeseries")
|
|
async def dashboard_timeseries(
|
|
project: Optional[str] = Query(None),
|
|
hours: int = Query(24, ge=1, le=720),
|
|
interval: str = Query("5m", max_length=16),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
"""Get time-series data for chart rendering."""
|
|
service = AnalyticsService(db)
|
|
return await service.get_time_series(project=project, hours=hours, interval=interval)
|