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,24 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { InputParseError } from "../../entities/errors/common";
|
||||
import type { Article } from "../../entities/models/article";
|
||||
import type { IGetArticlesUseCase } from "../../application/use-cases/get-articles.use-case";
|
||||
|
||||
const inputSchema = z.object({
|
||||
status: z.string().optional(),
|
||||
authorId: z.string().optional(),
|
||||
limit: z.number().optional(),
|
||||
offset: z.number().optional(),
|
||||
});
|
||||
|
||||
export type IGetArticlesController = ReturnType<typeof getArticlesController>;
|
||||
|
||||
export const getArticlesController =
|
||||
(getArticlesUseCase: IGetArticlesUseCase) =>
|
||||
async (input: Partial<z.infer<typeof inputSchema>>): Promise<Article[]> => {
|
||||
const parsed = inputSchema.safeParse(input);
|
||||
if (!parsed.success) {
|
||||
throw new InputParseError("Invalid get-articles input", { cause: parsed.error });
|
||||
}
|
||||
return getArticlesUseCase(parsed.data);
|
||||
};
|
||||
Reference in New Issue
Block a user