feat(review): 审稿选章可用——列章端点 + 选章下拉全章可见 + 默认最近章

- 后端新增 GET /projects/{id}/chapters(列真实存在的章 + has_draft/accepted/reviewed_at),TDD 10 测
- gen:api 重生成 TS 客户端(ChapterListItem)
- 选章下拉去掉 hidden(手机/窄屏也可切章);选项以真实章为准 + 大纲结构,
  无草稿章置灰(仅当前章例外),覆盖『写过但不在大纲』的章
- 无 ?chapter 时默认落到最近一个有草稿的章,而非硬编码第 1 章
This commit is contained in:
Yaojia Wang
2026-07-12 17:52:40 +02:00
parent 5f28491ad6
commit 9aa0cddeaf
12 changed files with 652 additions and 18 deletions

View File

@@ -56,6 +56,7 @@ from ww_api.schemas.injection import (
from ww_api.schemas.projects import (
AcceptRequest,
AcceptResponse,
ChapterListItem,
DraftResponse,
DraftSaveRequest,
DraftStreamRequest,
@@ -75,10 +76,12 @@ from ww_api.services.accept_service import (
assert_conflicts_resolved,
run_accept_transaction,
)
from ww_api.services.chapter_list import ChapterLister
from ww_api.services.credentials import STUB_OWNER_ID
from ww_api.services.digest_extraction import extract_digest_facts
from ww_api.services.foreshadow_scan import SessionFactory, run_overdue_scan
from ww_api.services.project_deps import (
get_chapter_lister,
get_chapter_repo,
get_clarify_gateway,
get_digest_append_repo,
@@ -115,6 +118,7 @@ _SSE_RESPONSE: dict[int | str, dict[str, Any]] = {
ProjectRepoDep = Annotated[ProjectRepo, Depends(get_project_repo)]
ChapterRepoDep = Annotated[ChapterRepo, Depends(get_chapter_repo)]
ChapterListerDep = Annotated[ChapterLister, Depends(get_chapter_lister)]
GatewayDep = Annotated[Gateway, Depends(get_writer_gateway)]
ReviewGatewayDep = Annotated[Gateway, Depends(get_review_gateway)]
DigestGatewayDep = Annotated[Gateway, Depends(get_digest_gateway)]
@@ -166,6 +170,28 @@ async def get_project(project_id: uuid.UUID, repo: ProjectRepoDep) -> ProjectRes
return _to_response(view)
@router.get("/{project_id}/chapters", responses=_NOT_FOUND)
async def list_chapters(
project_id: uuid.UUID,
project_repo: ProjectRepoDep,
lister: ChapterListerDep,
) -> list[ChapterListItem]:
"""列出该项目「真实存在的章」+ 可审/已审标记(审稿页选章下拉枚举)。
来源 `chapters`(草稿/accepted+ `chapter_reviews`,按章号去重升序。只读、不触 LLM。
项目不存在 → 404同其它端点owner 走 project_repo stub 校验)。
"""
if await project_repo.get(STUB_OWNER_ID, project_id) is None:
raise AppError(ErrorCode.NOT_FOUND, f"project {project_id} not found")
items = await lister.list_chapters(project_id)
log.info(
"chapters_listed",
project_id=str(project_id),
chapter_count=len(items),
)
return items
async def _injection_response(
repos: MemoryRepos,
project_id: uuid.UUID,