Release 1.7.0: Grafana catalog, ingress/IRM, tests
This commit is contained in:
@ -23,6 +23,11 @@ class TaskCreate(BaseModel):
|
||||
incident_id: UUID | None = None
|
||||
|
||||
|
||||
class TaskPatch(BaseModel):
|
||||
title: str | None = Field(default=None, min_length=1, max_length=500)
|
||||
status: str | None = Field(default=None, max_length=64)
|
||||
|
||||
|
||||
def register_events(_bus: EventBus, _pool: asyncpg.Pool | None = None) -> None:
|
||||
pass
|
||||
|
||||
@ -114,6 +119,63 @@ async def create_task_api(body: TaskCreate, pool: asyncpg.Pool | None = Depends(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{task_id}")
|
||||
async def get_task_api(task_id: UUID, pool: asyncpg.Pool | None = Depends(get_pool)):
|
||||
if pool is None:
|
||||
raise HTTPException(status_code=503, detail="database disabled")
|
||||
async with pool.acquire() as conn:
|
||||
row = await conn.fetchrow(
|
||||
"""
|
||||
SELECT id, incident_id, title, status, created_at
|
||||
FROM tasks WHERE id = $1::uuid
|
||||
""",
|
||||
task_id,
|
||||
)
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="not found")
|
||||
return {
|
||||
"id": str(row["id"]),
|
||||
"incident_id": str(row["incident_id"]) if row["incident_id"] else None,
|
||||
"title": row["title"],
|
||||
"status": row["status"],
|
||||
"created_at": row["created_at"].isoformat() if row["created_at"] else None,
|
||||
}
|
||||
|
||||
|
||||
@router.patch("/{task_id}")
|
||||
async def patch_task_api(
|
||||
task_id: UUID,
|
||||
body: TaskPatch,
|
||||
pool: asyncpg.Pool | None = Depends(get_pool),
|
||||
):
|
||||
if pool is None:
|
||||
raise HTTPException(status_code=503, detail="database disabled")
|
||||
if body.title is None and body.status is None:
|
||||
raise HTTPException(status_code=400, detail="no fields to update")
|
||||
async with pool.acquire() as conn:
|
||||
row = await conn.fetchrow(
|
||||
"""
|
||||
UPDATE tasks SET
|
||||
title = COALESCE($2, title),
|
||||
status = COALESCE($3, status)
|
||||
WHERE id = $1::uuid
|
||||
RETURNING id, incident_id, title, status, created_at
|
||||
""",
|
||||
task_id,
|
||||
body.title.strip() if body.title is not None else None,
|
||||
body.status,
|
||||
)
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="not found")
|
||||
return {
|
||||
"id": str(row["id"]),
|
||||
"incident_id": str(row["incident_id"]) if row["incident_id"] else None,
|
||||
"title": row["title"],
|
||||
"status": row["status"],
|
||||
"created_at": row["created_at"].isoformat() if row["created_at"] else None,
|
||||
}
|
||||
|
||||
|
||||
@ui_router.get("/", response_class=HTMLResponse)
|
||||
async def tasks_ui_home(request: Request):
|
||||
pool = get_pool(request)
|
||||
|
||||
Reference in New Issue
Block a user