mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
카테고리 페이지에 파일 목록 부분 구현
This commit is contained in:
25
src/routes/api/category/[id]/file/add/+server.ts
Normal file
25
src/routes/api/category/[id]/file/add/+server.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { categoryFileAddRequest } from "$lib/server/schemas";
|
||||
import { addCategoryFile } from "$lib/server/services/category";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ locals, params, request }) => {
|
||||
const { userId } = await authorize(locals, "activeClient");
|
||||
|
||||
const paramsZodRes = z
|
||||
.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
})
|
||||
.safeParse(params);
|
||||
if (!paramsZodRes.success) error(400, "Invalid path parameters");
|
||||
const { id } = paramsZodRes.data;
|
||||
|
||||
const bodyZodRes = categoryFileAddRequest.safeParse(await request.json());
|
||||
if (!bodyZodRes.success) error(400, "Invalid request body");
|
||||
const { file } = bodyZodRes.data;
|
||||
|
||||
await addCategoryFile(userId, id, file);
|
||||
return text("File added", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
17
src/routes/api/category/[id]/file/list/+server.ts
Normal file
17
src/routes/api/category/[id]/file/list/+server.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { error, json } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { categoryFileListResponse, type CategoryFileListResponse } from "$lib/server/schemas";
|
||||
import { getCategoryFiles } from "$lib/server/services/category";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const GET: RequestHandler = async ({ locals, params }) => {
|
||||
const { userId } = await authorize(locals, "activeClient");
|
||||
|
||||
const zodRes = z.object({ id: z.coerce.number().int().positive() }).safeParse(params);
|
||||
if (!zodRes.success) error(400, "Invalid path parameters");
|
||||
const { id } = zodRes.data;
|
||||
|
||||
const { files } = await getCategoryFiles(userId, id);
|
||||
return json(categoryFileListResponse.parse({ files }) as CategoryFileListResponse);
|
||||
};
|
||||
Reference in New Issue
Block a user