"""Dashboard API""" from datetime import datetime from fastapi import APIRouter, Depends, Query from sqlalchemy.ext.asyncio import AsyncSession from app.core.database import get_db from app.services.dashboard_service import ( get_dashboard_stats, DashboardStats, get_recent_activity, RecentActivity, ) router = APIRouter(prefix="/dashboard", tags=["管理看板"]) @router.get("/stats", response_model=DashboardStats) async def dashboard_stats(db: AsyncSession = Depends(get_db)): return await get_dashboard_stats(db) @router.get("/recent-activity", response_model=list[RecentActivity]) async def recent_activity( limit: int = Query(10, ge=1, le=50), since: str | None = Query(None, description="起始日期 ISO格式 如 2026-08-12T00:00:00"), until: str | None = Query(None, description="截止日期 ISO格式"), db: AsyncSession = Depends(get_db), ): """最近任务动态 — 支持日期范围筛选""" since_dt = datetime.fromisoformat(since) if since else None until_dt = datetime.fromisoformat(until) if until else None return await get_recent_activity(db, limit, since=since_dt, until=until_dt)