refactor(blog): factory-style use cases + per-use-case controllers + getArticleBySlug
- Use cases (create-article, get-articles, get-article-by-slug NEW) → factory functions - Controllers split: articles.controller.ts → 3 single-responsibility files - DI module wires factories with .toDynamicValue() - tRPC router resolves controllers via container Refactor log: §2, §3, §4.1, §4.2, §5.1 Spec: §6.2 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { InputParseError } from "../../entities/errors/common";
|
||||
import type { Article } from "../../entities/models/article";
|
||||
import type { IGetArticleBySlugUseCase } from "../../application/use-cases/get-article-by-slug.use-case";
|
||||
|
||||
const inputSchema = z.object({
|
||||
slug: z.string().min(1),
|
||||
});
|
||||
|
||||
export type IGetArticleBySlugController = ReturnType<typeof getArticleBySlugController>;
|
||||
|
||||
export const getArticleBySlugController =
|
||||
(getArticleBySlugUseCase: IGetArticleBySlugUseCase) =>
|
||||
async (input: Partial<z.infer<typeof inputSchema>>): Promise<Article> => {
|
||||
const parsed = inputSchema.safeParse(input);
|
||||
if (!parsed.success) {
|
||||
throw new InputParseError("Invalid get-article-by-slug input", { cause: parsed.error });
|
||||
}
|
||||
return getArticleBySlugUseCase(parsed.data);
|
||||
};
|
||||
Reference in New Issue
Block a user