37ccaa4fdc
Service organization (19 files moved into 6 subpackages): - services/instance/ — event_bus, health_monitor, lifecycle_hooks - services/config/ — config_profile_resolver - services/git/ — clone, git_operations, git_service - services/build/ — docker_build, manifest_compiler - services/terminal/ — terminal_manager, terminal_session - services/shared/ — correlation, file_service, notification_service, permission_fixer, readiness_probe, ssh_keys, tunnel, workspace_manager API router organization (16 files moved into 6 subpackages): - api/tool/ — tool_instances, tool_types, tool_definitions, tool_types_validation, sessions (extracted from tool_instances) - api/config/ — config_profiles, user_config - api/workspace/ — workspaces, workspace_files, workspace_git, workspace_instances - api/user/ — users, auth, ssh_keys - api/project/ — projects, git_repositories - api/system/ — health, events, notifications, dashboard, terminal, instance_proxy Updated main.py imports and all __init__.py re-exports. Sessions router extracted from tool_instances.py into api/tool/sessions.py. Quality gates: py_compile passed, ruff passed.
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
import uuid
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy import func, select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from src.auth.dependencies import get_current_user_id, get_db_session
|
|
from src.models import GitRepository
|
|
from src.models.project import Project
|
|
from src.models import SSHKey
|
|
|
|
router = APIRouter(prefix="/dashboard", tags=["dashboard"])
|
|
|
|
|
|
@router.get(
|
|
"/summary",
|
|
summary="Get dashboard summary",
|
|
description="Get a summary of the user's projects, repositories, SSH keys, and recent activity.",
|
|
)
|
|
async def get_dashboard_summary(
|
|
user_id: uuid.UUID = Depends(get_current_user_id),
|
|
session: AsyncSession = Depends(get_db_session),
|
|
) -> dict:
|
|
"""Get a summary of the user's dashboard data.
|
|
|
|
Args:
|
|
user_id: ID of the authenticated user.
|
|
session: Database session.
|
|
|
|
Returns:
|
|
Dictionary with counts of projects, repositories, SSH keys, and recent activity.
|
|
"""
|
|
# Count user's projects
|
|
projects_result = await session.execute(
|
|
select(func.count()).select_from(Project).where(Project.owner_id == user_id)
|
|
)
|
|
projects_count = projects_result.scalar() or 0
|
|
|
|
# Count user's repositories
|
|
repos_result = await session.execute(
|
|
select(func.count()).select_from(GitRepository).where(GitRepository.owner_id == user_id)
|
|
)
|
|
repos_count = repos_result.scalar() or 0
|
|
|
|
# Count user's SSH keys
|
|
ssh_keys_result = await session.execute(
|
|
select(func.count()).select_from(SSHKey).where(SSHKey.user_id == user_id)
|
|
)
|
|
ssh_keys_count = ssh_keys_result.scalar() or 0
|
|
|
|
# Get recent activity (latest 5 projects)
|
|
recent_projects = await session.execute(
|
|
select(Project)
|
|
.where(Project.owner_id == user_id)
|
|
.order_by(Project.created_at.desc())
|
|
.limit(5)
|
|
)
|
|
recent_activity = [f"Created project: {p.name}" for p in recent_projects.scalars().all()]
|
|
|
|
return {
|
|
"projects": projects_count,
|
|
"repositories": repos_count,
|
|
"sshKeys": ssh_keys_count,
|
|
"recentActivity": recent_activity,
|
|
}
|