首次发布git
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const id = (await params).id;
|
||||
try {
|
||||
const page = await prisma.page.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!page) return NextResponse.json({ error: 'Page not found' }, { status: 404 });
|
||||
return NextResponse.json({ ...page, tags: JSON.parse(page.tags || "[]") });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Error fetching page' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const id = (await params).id;
|
||||
try {
|
||||
const body = await request.json();
|
||||
// Separate update logic for flexibility (e.g. only updating title)
|
||||
const updateData: any = {};
|
||||
if (body.title !== undefined) updateData.title = body.title;
|
||||
if (body.content !== undefined) updateData.content = body.content;
|
||||
if (body.parentId !== undefined) updateData.parentId = body.parentId;
|
||||
if (body.tags !== undefined) updateData.tags = JSON.stringify(body.tags);
|
||||
if (body.icon !== undefined) updateData.icon = body.icon;
|
||||
if (body.isLocked !== undefined) updateData.isLocked = body.isLocked;
|
||||
|
||||
const page = await prisma.page.update({
|
||||
where: { id },
|
||||
data: updateData,
|
||||
});
|
||||
return NextResponse.json({ ...page, tags: JSON.parse(page.tags || "[]") });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Error updating page' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const id = (await params).id;
|
||||
try {
|
||||
await prisma.page.delete({
|
||||
where: { id },
|
||||
});
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Error deleting page' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user