Kairo-Jinkendo/backend/routers/blockers.py
Lars fe3bc4f057
All checks were successful
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 58s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s
AP0.8: Operating Model Extension I (Attention, Blocker, Backlog, Milestone)
Schema 007, regelbasierte Attention/NextAction im Data Layer, CRUD fuer Blocker/Backlog/Meilensteine, Workspace-Widget und Initiative-Detail-Sektionen. 25 Capabilities. Tests fuer Remote-Pytest auf Pi angepasst (conftest Session-Guard).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-05 15:11:15 +02:00

78 lines
2.4 KiB
Python

"""Blocker API — AP0.8b."""
from __future__ import annotations
from typing import Literal, Optional
from capabilities import require_capability
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field
from services import blockers as blocker_service
from tenant_context import TenantContext
router = APIRouter(prefix="/api/blockers", tags=["blockers"])
class BlockerCreateRequest(BaseModel):
title: str = Field(min_length=1, max_length=255)
description: str = ""
status: Literal["open", "in_progress", "resolved", "accepted_risk", "dismissed"] = "open"
action_id: Optional[str] = None
set_action_blocked: bool = False
class BlockerUpdateRequest(BaseModel):
title: Optional[str] = Field(default=None, min_length=1, max_length=255)
description: Optional[str] = None
status: Optional[
Literal["open", "in_progress", "resolved", "accepted_risk", "dismissed"]
] = None
action_id: Optional[str] = None
clear_action_id: bool = False
@router.get("/{blocker_id}")
def get_blocker(
blocker_id: str,
ctx: TenantContext = Depends(require_capability("kairo.blocker.read")),
):
item = blocker_service.get_blocker(tenant_id=ctx.tenant_id, blocker_id=blocker_id)
if not item:
raise HTTPException(status_code=404, detail="Blocker nicht gefunden")
return item
@router.patch("/{blocker_id}")
def update_blocker(
blocker_id: str,
body: BlockerUpdateRequest,
ctx: TenantContext = Depends(require_capability("kairo.blocker.manage")),
):
try:
item = blocker_service.update_blocker(
tenant_id=ctx.tenant_id,
blocker_id=blocker_id,
user_id=ctx.user_id,
title=body.title,
description=body.description,
status=body.status,
action_id=body.action_id,
clear_action_id=body.clear_action_id,
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
if not item:
raise HTTPException(status_code=404, detail="Blocker nicht gefunden")
return item
@router.delete("/{blocker_id}", status_code=204)
def delete_blocker(
blocker_id: str,
ctx: TenantContext = Depends(require_capability("kairo.blocker.manage")),
):
if not blocker_service.delete_blocker(
tenant_id=ctx.tenant_id, blocker_id=blocker_id, user_id=ctx.user_id
):
raise HTTPException(status_code=404, detail="Blocker nicht gefunden")