Files
page-builder/src/app/api/projects/[slug]/route.ts
T
jaybe 17bfac62ed
CI / test (push) Failing after 7m39s
CI / pr_and_merge (push) Has been skipped
프로젝트 저장 및 목록
2025-11-29 22:05:25 +09:00

44 lines
1.3 KiB
TypeScript

import { NextResponse } from "next/server";
import { PrismaClient } from "@/generated/prisma/client";
const prisma = new PrismaClient();
export async function GET(_request: Request, context: { params: { slug: string } | Promise<{ slug: string }> }) {
const { slug } = await context.params;
const project = await prisma.project.findUnique({
where: { slug },
});
if (!project) {
return NextResponse.json({ message: "프로젝트를 찾을 수 없습니다." }, { status: 404 });
}
return NextResponse.json(project, { status: 200 });
}
export async function DELETE(
_request: Request,
context: { params: { slug: string } | Promise<{ slug: string }> },
) {
const { slug } = await context.params;
try {
await prisma.project.delete({
where: { slug },
});
return NextResponse.json({ message: "프로젝트가 삭제되었습니다." }, { status: 200 });
} catch (error: any) {
// Prisma NotFound 에러 코드(P2025)가 떨어지는 경우 404 로 매핑한다.
if (error?.code === "P2025") {
return NextResponse.json({ message: "프로젝트를 찾을 수 없습니다." }, { status: 404 });
}
return NextResponse.json(
{ message: "프로젝트 삭제 중 오류가 발생했습니다.", error: error?.message },
{ status: 500 },
);
}
}