refactor(navigation): factory-style use case + controller

- Use case (get-header) → factory function with IGetHeaderUseCase alias
- Controller renamed header.controller.ts → get-header.controller.ts (verb-noun); converted to factory function with IGetHeaderController alias
- DI module wires factories with .toDynamicValue()
- tRPC router resolves controller via container
- Use case + controller tests refactored to direct factory injection (no container rebinding)
- container.test.ts verifies IGetHeaderUseCase + IGetHeaderController symbols

Refactor log: §1, §4.1, §4.2, §5.1
Spec: §6.4

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 00:19:15 +02:00
parent 353a41b244
commit 69623b995d
11 changed files with 104 additions and 46 deletions

View File

@@ -20,6 +20,10 @@ single follow-up pass.
## 1. File renames (before → after)
### Task 7: Controller rename
- `packages/navigation/src/interface-adapters/controllers/header.controller.ts``get-header.controller.ts` (verb-noun convention; git mv — history preserved)
### Task 3: File and class renames
File renames — 27 files (git mv — history preserved):
@@ -146,7 +150,7 @@ Entity model moves (git mv — history preserved):
### 4.1 Use cases — factory function pattern
Applied to all 3 auth use cases (`sign-in`, `sign-up`, `sign-out`) in Task 4, all 3 blog use cases (`get-articles`, `create-article`, `get-article-by-slug` NEW) in Task 5, and both marketing-pages use cases (`get-page-by-slug`, `get-site-settings`) in Task 6:
Applied to all 3 auth use cases (`sign-in`, `sign-up`, `sign-out`) in Task 4, all 3 blog use cases (`get-articles`, `create-article`, `get-article-by-slug` NEW) in Task 5, both marketing-pages use cases (`get-page-by-slug`, `get-site-settings`) in Task 6, and the single navigation use case (`get-header`) in Task 7:
- Use cases are now factory functions: `(deps) => async (input) => result`
- Each file exports `export type I*UseCase = ReturnType<typeof *UseCase>` for DI typing
@@ -154,6 +158,7 @@ Applied to all 3 auth use cases (`sign-in`, `sign-up`, `sign-out`) in Task 4, al
- Tests construct mocks directly: `const useCase = getArticlesUseCase(repo); await useCase({ status: "draft" });`
- NEW `getArticleBySlugUseCase`: previously the slug lookup bypassed the use case layer (controller called repo directly); now the use case owns the `ArticleNotFoundError` throw
- marketing-pages: `getPageBySlugUseCase(pagesRepo) => async ({ slug }) => Page | undefined` and `getSiteSettingsUseCase(siteSettingsRepo) => async () => SiteSettings`
- navigation: `getHeaderUseCase(headerRepo) => async () => Header`; `IGetHeaderUseCase` type alias exported
### 4.2 Controllers — one per use case
@@ -162,6 +167,7 @@ Applied to all 3 auth controllers (`sign-in`, `sign-up`, `sign-out`) in Task 4;
- Controllers were already split for auth (one file per use case) — Task 4 refactors them to factory functions
- Blog: the multi-method `articles.controller.ts` is deleted and replaced by 3 single-responsibility files
- Marketing-pages: the multi-method `pages.controller.ts` is deleted and replaced by 2 single-responsibility files (`get-page-by-slug.controller.ts`, `get-site-settings.controller.ts`)
- Navigation: `header.controller.ts` renamed to `get-header.controller.ts` (verb-noun) and converted to factory function; exports `IGetHeaderController` type alias
- Factory pattern: `(useCase: I*UseCase) => async (input) => result`
- Each exports `export type I*Controller = ReturnType<typeof *Controller>`
- Validation (Zod `safeParse`) stays inside the controller factory; throws `InputParseError` on failure
@@ -201,6 +207,12 @@ Applied to `packages/auth/src/di/module.ts` (Task 4), `packages/blog/src/di/modu
- Repository bindings remain `.to(MockPagesRepository)` and `.to(MockSiteSettingsRepository)` as defaults
- tRPC router updated to resolve controllers via `marketingPagesContainer.get<IXController>(MARKETING_PAGES_SYMBOLS.IXController)`
**navigation:**
- `NAVIGATION_SYMBOLS` expanded with 2 new keys: `IGetHeaderUseCase`, `IGetHeaderController`
- Use case and controller bound with `.toDynamicValue((ctx) => factoryFn(ctx.container.get(...)))` — same pattern as other features
- Repository binding remains `.to(MockHeaderRepository)` as default
- tRPC router updated to resolve controller via `navigationContainer.get<IGetHeaderController>(NAVIGATION_SYMBOLS.IGetHeaderController)`
### 5.2 Mock siblings registered as default bindings
- `MockUsersRepository` and `MockAuthenticationService` remain the default bindings in `AuthModule`