refactor(media): unify use-case I/O schemas + presenter + feature error map
Per Plan 9 (spec R1-R28): - Use cases: input + output schemas (getMedia, listMedia); deleteMedia has input schema only (void output, R12 — no presenter). - Controllers: unknown input + identity presenter on getMedia/listMedia; Promise<void> on deleteMedia. - New integrations/api/procedures.ts with mediaProcedure ([InputParseError → BAD_REQUEST], [MediaNotFoundError → NOT_FOUND]). - Router uses mediaProcedure + .input(xInputSchema). - src/index.ts exports schemas + types; src/ui/index.ts placeholder (media has no queries today); package.json adds ./ui subpath. - R25 + R26 tests added. Refactor log: §1, §2, §3.1, §3.2, §3.3, §5.1, §5.2, §6.1, §6.2 Spec: R1–R6, R8–R15, R18–R20, R22–R26 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
import { z } from "zod";
|
||||
import { InputParseError } from "../../entities/errors/common";
|
||||
import type { Media } from "../../entities/models/media";
|
||||
import type { IGetMediaUseCase } from "../../application/use-cases/get-media.use-case";
|
||||
import {
|
||||
getMediaInputSchema,
|
||||
type GetMediaOutput,
|
||||
type IGetMediaUseCase,
|
||||
} from "../../application/use-cases/get-media.use-case";
|
||||
|
||||
const inputSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
});
|
||||
function presenter(value: GetMediaOutput) {
|
||||
return value;
|
||||
}
|
||||
|
||||
export type IGetMediaController = ReturnType<typeof getMediaController>;
|
||||
|
||||
export const getMediaController =
|
||||
(getMediaUseCase: IGetMediaUseCase) =>
|
||||
async (input: Partial<z.infer<typeof inputSchema>>): Promise<Media> => {
|
||||
const parsed = inputSchema.safeParse(input);
|
||||
async (input: unknown): Promise<ReturnType<typeof presenter>> => {
|
||||
const parsed = getMediaInputSchema.safeParse(input);
|
||||
if (!parsed.success) {
|
||||
throw new InputParseError("Invalid get-media input", { cause: parsed.error });
|
||||
}
|
||||
return getMediaUseCase(parsed.data);
|
||||
const result = await getMediaUseCase(parsed.data);
|
||||
return presenter(result);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user