first commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from fastapi import APIRouter, Depends, Path, Query
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_database
|
||||
from app.db.repositories.repositories import TestRunRepository
|
||||
from app.schemas.api import ErrorResponse, ReportResponse
|
||||
from app.services.report_service import ReportService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/reports",
|
||||
response_model=list[ReportResponse],
|
||||
summary="列出测试汇总报告",
|
||||
description="按运行创建时间倒序返回实时计算的报告;`limit` 默认 50,最大 200。",
|
||||
)
|
||||
def list_reports(
|
||||
limit: int = Query(default=50, ge=1, le=200),
|
||||
db: Session = Depends(get_database),
|
||||
):
|
||||
service = ReportService(db)
|
||||
return [
|
||||
ReportResponse(run_id=run.id, summary=service.build_summary(run.id))
|
||||
for run in TestRunRepository(db).list(limit)
|
||||
]
|
||||
|
||||
|
||||
@router.get(
|
||||
"/reports/{run_id}",
|
||||
response_model=ReportResponse,
|
||||
summary="查询测试汇总报告",
|
||||
description="实时计算并返回某次测试运行的结构化汇总;运行不存在时返回 404。",
|
||||
responses={404: {"model": ErrorResponse, "description": "指定的测试运行不存在。"}},
|
||||
)
|
||||
def get_report(
|
||||
run_id: int = Path(description="要生成报告的测试运行 ID,必须为正整数。", gt=0),
|
||||
db: Session = Depends(get_database),
|
||||
):
|
||||
return ReportResponse(
|
||||
run_id=run_id,
|
||||
summary=ReportService(db).build_summary(run_id),
|
||||
)
|
||||
Reference in New Issue
Block a user