S04 の教材のコード(Result へ変更する前のコード)では、入力の検査と呼び出しだけが route に残り、ほかの処理は useCase(ユースケース。1つの業務の手順をまとめた関数)に移動済みです。deps は、予約を取得する Resolver と保存する Store をまとめた引数です。
-
S03(移動前): route は、入力の検査から監査まで、5つの処理を1つの関数に持っていました。
S03 の route examples/session-03/src/adaptor/primary/web/routes.ts:111-126const input = StartExaminationInput.parse({ appointmentId: context.req.param("appointmentId"), veterinarianId: raw.veterinarianId, })._unsafeUnwrap(); const current = appointmentOrThrow(repository, input.appointmentId); if (current.kind !== "CheckedIn") throw new Error("Invalid appointment state"); saveAndAppendAudit( repository, startExamination( current, input.veterinarianId, "2026-08-30T06:30:00.000Z", ), "ExaminationStarted", "2026-08-30T06:30:00.000Z", );- 1 入力の検査予約IDと獣医師IDの形を検証する
- 2 予約の取得予約IDで予約を取得する
- 3 状態の確認と遷移来院済みかを検証し、診察中にする
- 4 保存診察中の予約を保存する
- 5 監査診察を開始した記録を追加する
-
S04 の教材のコード(移動済み): route には入力の検査と呼び出しが残り、状態の確認と遷移は useCase の本体、予約の取得は Resolver、保存と監査は Store に移っています。
S04 の route examples/session-04/src/adaptor/primary/web/routes.ts:75-78,80-86const input = StartExaminationInput.parse({ appointmentId: context.req.param("appointmentId"), veterinarianId: raw.veterinarianId, })._unsafeUnwrap(); startExamination({ resolver: store, store, })({ ...input, examinationStartedAt: "2026-08-30T06:30:00.000Z", });useCase examples/session-04/src/useCase/startExamination.ts:17-29const appointment = ensureAppointmentFound( deps.resolver.resolveById(input.appointmentId), input.appointmentId, ); const checkedIn = ensureCheckedIn(appointment); const next = transitionToInExamination( checkedIn, input.veterinarianId, input.examinationStartedAt, ); deps.store.save(next); return next;- Resolver予約を取得するオブジェクト
deps.resolver.resolveById(…) - Store保存(状態の更新と監査記録の追加)
deps.store.save(…) - errors.ts失敗を検証する関数の置き場
ensureCheckedIn(…)
- Resolver予約を取得するオブジェクト
図の見出しのパスは、次のコードを指します。examples/session-04 は教材のコード(Result へ変更する前)、examples/session-04-solution は演習の解答です。「説明用のコード」は、本文のために用意した例です。