generated from coulomb/repo-seed
- Migration c5d6e7f8a9b0: domain_goals and repo_goals tables, repo_goal_id FK on workstreams - DomainGoal: one active per domain (partial unique index), status active/archived/superseded - RepoGoal: integer priority, status active/paused/completed/archived, optional domain_goal_id link - WorkstreamUpdate schema and router extended with repo_goal_id and repo_goal_id filter - 6 new MCP goal tools: create_domain_goal, get_domain_goals, activate_domain_goal, create_repo_goal, get_repo_goals, update_repo_goal - update_workstream MCP tool: patch any subset of workstream fields (title, description, owner, due_date, repo_goal_id, status) - get_domain_summary extended with goal_guidance (needs_workplan, alignment_warnings) signals - Dashboard goals.md page and docs/goals.md reference page - CLAUDE.md template updated to act on goal_guidance signals at session start - CUST-WP-0010 workplan for this feature Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
87 lines
2.8 KiB
Python
87 lines
2.8 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,
|
|
repo_goal_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 repo_goal_id:
|
|
q = q.where(Workstream.repo_goal_id == repo_goal_id)
|
|
if status:
|
|
q = q.where(Workstream.status == status)
|
|
q = q.order_by(Workstream.updated_at.desc())
|
|
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
|