From 27822de3e0cae0fff7391cab10d53459f04507a2 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Wed, 3 Jun 2026 23:52:12 +0000 Subject: [PATCH] Upload app/api/v1/dashboard.py --- app/api/v1/dashboard.py | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/api/v1/dashboard.py diff --git a/app/api/v1/dashboard.py b/app/api/v1/dashboard.py new file mode 100644 index 0000000..4796f36 --- /dev/null +++ b/app/api/v1/dashboard.py @@ -0,0 +1,49 @@ +"""Dashboard API endpoints: KPIs and activity feed.""" + +from __future__ import annotations + +from fastapi import APIRouter, Depends +from sqlalchemy.ext.asyncio import AsyncSession + +from app.core.db import get_db +from app.core.deps import get_current_user +from app.models.user import User +from app.schemas.dashboard import ActivityFeedItem, KPIOut +from app.services.dashboard_service import ( + get_activity_feed, + get_kpis, +) + +router = APIRouter(prefix="/dashboard", tags=["dashboard"]) + + +@router.get( + "/kpis", + response_model=KPIOut, + summary="Get dashboard KPIs (open deals, pipeline value, won this month, conversion rate)", +) +async def get_kpis_endpoint( + current_user: User = Depends(get_current_user), + db: AsyncSession = Depends(get_db), +) -> KPIOut: + kpis = await get_kpis(db, org_id=current_user.org_id) + return KPIOut(**kpis) # type: ignore[arg-type] + + +@router.get( + "/feed", + response_model=list[ActivityFeedItem], + summary="Get the latest 20 activities (sorted by created_at desc)", +) +async def get_activity_feed_endpoint( + limit: int = 20, + current_user: User = Depends(get_current_user), + db: AsyncSession = Depends(get_db), +) -> list[ActivityFeedItem]: + activities = await get_activity_feed( + db, org_id=current_user.org_id, limit=limit + ) + return [ActivityFeedItem.model_validate(a) for a in activities] + + +__all__ = ["router"]