Files
writer-work-flow/apps/api/ww_api/routers/jobs.py
Yaojia Wang 1392830e57 refactor(backend): jobs 读端点走 JobRepo 而非路由内裸 ORM
GET /jobs/{id} 原在路由里直接 select(Job) 裸 ORM 查询;改为经 get_job_repo
注入 JobRepo 调 .get(job_id),与项目其它端点的 Repository 分层一致,
测试可经 dependency_overrides 注 fake。行为不变(同一 session 同一查询)。
2026-07-08 12:35:09 +02:00

37 lines
961 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""长任务轮询端点 GET /jobs/:idARCH §7.4)。"""
from __future__ import annotations
import uuid
from typing import Annotated
from fastapi import APIRouter, Depends
from ww_core.domain import JobRepo
from ww_shared import AppError, ErrorCode, ErrorEnvelope
from ww_api.schemas.jobs import JobResponse
from ww_api.services.project_deps import get_job_repo
router = APIRouter(prefix="/jobs", tags=["jobs"])
@router.get(
"/{job_id}",
responses={404: {"model": ErrorEnvelope, "description": "job 不存在"}},
)
async def get_job(
job_id: uuid.UUID,
job_repo: Annotated[JobRepo, Depends(get_job_repo)],
) -> JobResponse:
job = await job_repo.get(job_id)
if job is None:
raise AppError(ErrorCode.NOT_FOUND, f"job {job_id} not found")
return JobResponse(
id=job.id,
kind=job.kind,
status=job.status,
progress=job.progress,
result=job.result,
error=job.error,
)