generated from coulomb/repo-seed
Implements CUST-WP-0007. Resolves inconsistencies I-1, I-2, I-5, I-6
identified in the GEMS audit (GenericEntityModellingSystem.md).
Pass 1 (e1f2a3b4c5d6): domain_id FK on extension_points and
technical_debt (replaces raw string column); repo_id FK on contributions.
Fixes domain-filtering bugs in EP/TD dashboard pages.
Pass 2 (f2a3b4c5d6e7): repo_id nullable FK on workstreams, aligning
the GEMS primary attachment with ADR-001 (repo > topic). Dashboard
pages updated to prefer repo->domain over topic->domain.
Pass 3 (a3b4c5d6e7f8): SBOMSnapshot container entity (GEMS Complex
between Repository and SBOMEntry). Ingest is now additive — each call
creates a new snapshot; history is retained. List/report endpoints
filter to latest snapshot per repo via _latest_snapshot_ids_subquery().
New endpoints: GET /sbom/snapshots/, GET /sbom/snapshots/{id}/.
Dashboard gains a Snapshot History section.
Also adds GEMS analysis artefacts: wiki/GEMS-StateHub-TypeRegistry.md,
wiki/GEMS-StateHub-SWOT.md, workplans/CUST-WP-0006 (analysis),
workplans/CUST-WP-0007 (migration, now completed).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
import uuid
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from api.database import get_session
|
|
from api.models.workstream import Workstream, WorkstreamStatus
|
|
from api.schemas.workstream import WorkstreamCreate, WorkstreamRead, WorkstreamUpdate
|
|
|
|
router = APIRouter(prefix="/workstreams", tags=["workstreams"])
|
|
|
|
|
|
@router.get("/", response_model=list[WorkstreamRead])
|
|
async def list_workstreams(
|
|
topic_id: uuid.UUID | None = None,
|
|
repo_id: uuid.UUID | None = None,
|
|
status: WorkstreamStatus | None = None,
|
|
session: AsyncSession = Depends(get_session),
|
|
) -> list[Workstream]:
|
|
q = select(Workstream)
|
|
if topic_id:
|
|
q = q.where(Workstream.topic_id == topic_id)
|
|
if repo_id:
|
|
q = q.where(Workstream.repo_id == repo_id)
|
|
if status:
|
|
q = q.where(Workstream.status == status)
|
|
q = q.order_by(Workstream.created_at)
|
|
result = await session.execute(q)
|
|
return list(result.scalars().all())
|
|
|
|
|
|
@router.post("/", response_model=WorkstreamRead, status_code=status.HTTP_201_CREATED)
|
|
async def create_workstream(
|
|
body: WorkstreamCreate,
|
|
session: AsyncSession = Depends(get_session),
|
|
) -> Workstream:
|
|
ws = Workstream(**body.model_dump())
|
|
session.add(ws)
|
|
await session.commit()
|
|
await session.refresh(ws)
|
|
return ws
|
|
|
|
|
|
@router.get("/{workstream_id}", response_model=WorkstreamRead)
|
|
async def get_workstream(
|
|
workstream_id: uuid.UUID,
|
|
session: AsyncSession = Depends(get_session),
|
|
) -> Workstream:
|
|
ws = await session.get(Workstream, workstream_id)
|
|
if ws is None:
|
|
raise HTTPException(status_code=404, detail="Workstream not found")
|
|
return ws
|
|
|
|
|
|
@router.patch("/{workstream_id}", response_model=WorkstreamRead)
|
|
async def update_workstream(
|
|
workstream_id: uuid.UUID,
|
|
body: WorkstreamUpdate,
|
|
session: AsyncSession = Depends(get_session),
|
|
) -> Workstream:
|
|
ws = await session.get(Workstream, workstream_id)
|
|
if ws is None:
|
|
raise HTTPException(status_code=404, detail="Workstream not found")
|
|
for field, value in body.model_dump(exclude_unset=True).items():
|
|
setattr(ws, field, value)
|
|
await session.commit()
|
|
await session.refresh(ws)
|
|
return ws
|
|
|
|
|
|
@router.delete("/{workstream_id}", response_model=WorkstreamRead)
|
|
async def archive_workstream(
|
|
workstream_id: uuid.UUID,
|
|
session: AsyncSession = Depends(get_session),
|
|
) -> Workstream:
|
|
ws = await session.get(Workstream, workstream_id)
|
|
if ws is None:
|
|
raise HTTPException(status_code=404, detail="Workstream not found")
|
|
ws.status = WorkstreamStatus.archived
|
|
await session.commit()
|
|
await session.refresh(ws)
|
|
return ws
|