Create a simple GET endpoint that queries the database and returns aggregated data.
The frontend team needs a quick way to show scan statistics on a dashboard. They want counts of findings, leads, and endpoints for a given scanβall in one API call.
Your job: Add a simple GET /v1/scans/{scan_id}/summary endpoint that returns these counts. This is your first touch of the platform codebase.
platform/
βββ api/
β βββ routes/
β β βββ v1/
β β βββ scans.py β Add your endpoint here
β β βββ findings.py
β β βββ leads.py
β βββ schemas/
β β βββ v1/
β β βββ scan.py β Add response schema here
β βββ dependencies/
β βββ db.py β TenantDB dependency
βββ db/
β βββ models/
β βββ scan.py
β βββ finding.py
β βββ lead.py
βββ server/
βββ app.py β FastAPI app
Depends(get_tenant_db)In platform/api/schemas/v1/scan.py, add:
from pydantic import BaseModel
class ScanSummaryResponse(BaseModel):
scan_id: UUID
findings_count: int
leads_count: int
endpoints_count: int
In platform/api/routes/v1/scans.py, add:
from api.schemas.v1.scan import ScanSummaryResponse
@router.get("/v1/scans/{scan_id}/summary", response_model=ScanSummaryResponse)
async def get_scan_summary(
scan_id: UUID,
user: ActiveUser = Depends(get_current_user),
tenant_db: TenantDB = Depends(get_tenant_db),
) -> ScanSummaryResponse:
"""Get summary counts for a scan."""
# Verify scan exists and belongs to tenant
service = ScanService(tenant_db, encryption_service)
try:
scan = await service.get_scan(scan_id)
except NotFoundError:
raise HTTPException(status_code=404, detail="Scan not found")
# Count related entities
# Option 1: Use existing services
finding_service = FindingService(tenant_db, service)
lead_service = LeadService(tenant_db)
endpoint_service = EndpointService(tenant_db)
# Option 2: Direct count queries (more efficient)
# findings_count = await tenant_db.session.scalar(
# select(func.count(Finding.id)).where(Finding.scan_id == scan_id)
# )
return ScanSummaryResponse(
scan_id=scan_id,
findings_count=..., # Your implementation
leads_count=...,
endpoints_count=...,
)
# Start the platform
cd ~/projects/tenzai
mise run platform
# Test your endpoint (replace with actual IDs)
curl http://localhost:8000/v1/scans/{scan_id}/summary \
-H "Authorization: Bearer $TOKEN"
# Or use the Swagger UI
open http://localhost:8000/docs
ScanSummaryResponse/docs