diff --git a/src/features/tech-log/adapters/http/http-public-content-gateway.ts b/src/features/tech-log/adapters/http/http-public-content-gateway.ts index e91247a..74d9dae 100644 --- a/src/features/tech-log/adapters/http/http-public-content-gateway.ts +++ b/src/features/tech-log/adapters/http/http-public-content-gateway.ts @@ -83,6 +83,13 @@ export const REFERENCE_RELATION_LABELS = Object.freeze({ relatedReferences: "함께 보는 기준", }); +export const CONCEPT_RELATION_LABELS = Object.freeze({ + supportingCases: "이 개념을 확인한 기록", + relatedReferences: "함께 보는 기준", + relatedConcepts: "이어지는 개념", + relatedDecisions: "이 개념을 쓴 결정", +}); + export const QUESTION_RELATION_LABELS = Object.freeze({ resultCase: "이 질문에서 나온 기록", producedDecision: "이 질문이 이끈 결정", @@ -162,8 +169,20 @@ export function createHttpPublicContentGateway( kind: K, slug: string, ): Promise | undefined> { - const operationId = - kind === "CASE" ? "getPublicCase" : kind === "REFERENCE" ? "getPublicReference" : "getPublicQuestion"; + /* + 삼항으로 이어 붙이면 마지막 else 가 모르는 종류를 다 받아 간다 — 개념이 그렇게 질문 + 조회로 떨어졌고, `/concepts/{slug}` 화면이 `/api/v1/public/questions/{slug}` 를 불러 + 404 를 받아 「페이지를 찾을 수 없습니다」가 났다. 삭제 경로에서 겪은 것과 같은 모양이다. + + 표로 두면 종류가 늘 때 빠진 자리를 타입이 잡는다. + */ + const OPERATIONS: Record = { + CASE: "getPublicCase", + REFERENCE: "getPublicReference", + QUESTION: "getPublicQuestion", + CONCEPT: "getPublicConcept", + }; + const operationId = OPERATIONS[kind]; const detail = await read>>(operationId, { slug }); if (detail === NOT_FOUND) return undefined; @@ -256,6 +275,45 @@ export function createHttpPublicContentGateway( }) as unknown as Extract; } + /* + 개념은 Case 와 같은 본문 규칙을 쓴다 — Markdown 한 덩어리에 `:::evidence` 로 도식을 + 끌어온다. 이 분기가 없던 동안 개념은 마지막 return(질문 매핑)으로 떨어졌고, 그전에 + 이미 질문 조회 API 를 부르고 있어 화면이 통째로 404 였다. + */ + if (kind === "CONCEPT") { + const body = (detail.concept as Readonly>) ?? {}; + return Object.freeze({ + ...baseOf("CONCEPT", slug, { + title: body.title as string, + summary: (body.summary as string) ?? "", + path: canonicalPath, + primaryTopic: body.primaryTopic as never, + primaryProject: body.primaryProject as never, + publishedAt: body.publishedAt as string, + relations: flattenRelations(groups, CONCEPT_RELATION_LABELS), + }), + kind: "CONCEPT", + basisVersion: (body.basisVersion as string) ?? "", + content: (body.content as string) ?? "", + bodyAssets: Object.freeze( + ((body.bodyAssets as readonly Readonly>[]) ?? []).map((asset) => + Object.freeze({ + assetKey: asset.assetKey as string, + assetId: asset.assetId as string, + url: asset.url as string, + contentType: asset.contentType as string, + altText: (asset.altText as string) ?? "", + width: (asset.width as number) ?? null, + height: (asset.height as number) ?? null, + decorative: Boolean(asset.decorative), + }), + ), + ), + sections: markdownSections(body.content as string), + }) as unknown as Extract; + } + + const body = (detail.question as Readonly>) ?? {}; /* `points` 는 그룹 이름을 키로 갖는 객체다 — 계약의 `QuestionPointGroup`. 여기서는 diff --git a/src/features/tech-log/contracts/tech-log-public-contract-contribution.ts b/src/features/tech-log/contracts/tech-log-public-contract-contribution.ts index dac5eda..21e56b5 100644 --- a/src/features/tech-log/contracts/tech-log-public-contract-contribution.ts +++ b/src/features/tech-log/contracts/tech-log-public-contract-contribution.ts @@ -125,6 +125,7 @@ const HTTP_CONTRACTS = Object.freeze([ publicRead("getPublicCase", `${P}/cases/{slug}`, 524_288, bySlug), publicRead("getPublicReference", `${P}/references/{slug}`, 524_288, bySlug), publicRead("getPublicQuestion", `${P}/questions/{slug}`, 524_288, bySlug), + publicRead("getPublicConcept", `${P}/concepts/{slug}`, 524_288, bySlug), publicRead("listPublicProjects", `${P}/projects`, 262_144), publicRead("getPublicProject", `${P}/projects/{slug}`, 262_144, bySlug), publicRead("listPublicProjectDecisions", `${P}/projects/{slug}/decisions`, 262_144, bySlug), diff --git a/tests/features/tech-log/public-read-routing.test.ts b/tests/features/tech-log/public-read-routing.test.ts new file mode 100644 index 0000000..e0eed1b --- /dev/null +++ b/tests/features/tech-log/public-read-routing.test.ts @@ -0,0 +1,39 @@ +import assert from "node:assert/strict"; +import { test } from "vitest"; + +import { TECH_LOG_PUBLIC_CONTRIBUTION } from "../../../src/features/tech-log/contracts/tech-log-public-contract-contribution.ts"; + +/** + * 종류마다 읽는 주소가 다르다. 이 대응이 어긋나면 화면이 다른 종류의 API 를 부른다. + * + *

실제로 그렇게 났다: 게이트웨이가 종류를 삼항으로 이어 붙여 마지막 else 가 남은 것을 다 + * 받아 갔고, `/concepts/{slug}` 화면이 `/api/v1/public/questions/{slug}` 를 불러 404 를 받았다. + * 계약 타입에는 `getPublicConcept` 이 있었지만 기여 목록에 등록되지 않아 부를 수도 없었다. + * 삭제 경로에서 겪은 것과 같은 모양이다. + */ +const EXPECTED = { + CASE: { operationId: "getPublicCase", path: "/api/v1/public/cases/{slug}" }, + REFERENCE: { operationId: "getPublicReference", path: "/api/v1/public/references/{slug}" }, + QUESTION: { operationId: "getPublicQuestion", path: "/api/v1/public/questions/{slug}" }, + CONCEPT: { operationId: "getPublicConcept", path: "/api/v1/public/concepts/{slug}" }, +} as const; + +test("문서 종류마다 자기 조회 주소가 있고 서로 겹치지 않는다", () => { + const byId = new Map( + TECH_LOG_PUBLIC_CONTRIBUTION.http.map((entry) => [entry.contract.operationId, entry]), + ); + + const paths = new Set(); + for (const [kind, expected] of Object.entries(EXPECTED)) { + const installed = byId.get(expected.operationId); + assert.ok(installed, `${kind} 를 읽는 ${expected.operationId} 가 기여 목록에 있어야 한다`); + assert.equal(installed.contract.method, "GET"); + assert.equal( + installed.contract.pathTemplate, + expected.path, + `${kind} 는 자기 주소로 나가야 한다`, + ); + assert.ok(!paths.has(expected.path), `${kind} 가 다른 종류와 같은 주소를 쓴다`); + paths.add(expected.path); + } +});