프로젝트 저장 및 목록
CI / test (push) Failing after 7m39s
CI / pr_and_merge (push) Has been skipped

This commit is contained in:
2025-11-29 22:05:25 +09:00
parent 1f085bd64c
commit 17bfac62ed
15 changed files with 1765 additions and 179 deletions
+27 -8
View File
@@ -3,14 +3,8 @@ import { PrismaClient } from "@/generated/prisma/client";
const prisma = new PrismaClient();
interface Params {
params: {
slug: string;
};
}
export async function GET(_request: Request, { params }: Params) {
const { slug } = params;
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 },
@@ -22,3 +16,28 @@ export async function GET(_request: Request, { params }: Params) {
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 },
);
}
}
+31 -2
View File
@@ -3,6 +3,30 @@ import { PrismaClient } from "@/generated/prisma/client";
const prisma = new PrismaClient();
export async function GET(_request: Request) {
try {
const projects = await prisma.project.findMany({
orderBy: { createdAt: "desc" },
take: 50,
select: {
id: true,
title: true,
slug: true,
status: true,
createdAt: true,
updatedAt: true,
},
});
return NextResponse.json(projects, { status: 200 });
} catch (error: any) {
return NextResponse.json(
{ message: "프로젝트 목록을 가져오는 중 오류가 발생했습니다.", error: error?.message },
{ status: 500 },
);
}
}
export async function POST(request: Request) {
const body = await request.json();
const { title, slug, contentJson } = body;
@@ -12,8 +36,13 @@ export async function POST(request: Request) {
}
try {
const project = await prisma.project.create({
data: {
const project = await prisma.project.upsert({
where: { slug },
update: {
title,
contentJson,
},
create: {
title,
slug,
contentJson,