Initial commit - Sitemap Builder app

This commit is contained in:
Karol Głowacki
2026-01-09 18:52:15 +01:00
parent 4e5625f03e
commit 318dcc88ac
54 changed files with 7969 additions and 103 deletions

View File

@@ -0,0 +1,58 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
interface Params {
params: Promise<{ id: string }>;
}
// GET links for a node
export async function GET(request: NextRequest, { params }: Params) {
try {
const { id } = await params;
const links = await prisma.link.findMany({
where: { nodeId: id },
orderBy: { createdAt: "desc" },
});
return NextResponse.json(links);
} catch (error) {
console.error("Failed to fetch links:", error);
return NextResponse.json(
{ error: "Failed to fetch links" },
{ status: 500 }
);
}
}
// POST add a link to a node
export async function POST(request: NextRequest, { params }: Params) {
try {
const { id: nodeId } = await params;
const body = await request.json();
const { url, label } = body;
if (!url) {
return NextResponse.json(
{ error: "URL is required" },
{ status: 400 }
);
}
const link = await prisma.link.create({
data: {
nodeId,
url,
label: label || null,
},
});
return NextResponse.json(link, { status: 201 });
} catch (error) {
console.error("Failed to create link:", error);
return NextResponse.json(
{ error: "Failed to create link" },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,76 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
interface Params {
params: Promise<{ id: string }>;
}
// GET node details
export async function GET(request: NextRequest, { params }: Params) {
try {
const { id } = await params;
const node = await prisma.node.findUnique({
where: { id },
include: {
attachments: true,
links: true,
},
});
if (!node) {
return NextResponse.json(
{ error: "Node not found" },
{ status: 404 }
);
}
return NextResponse.json(node);
} catch (error) {
console.error("Failed to fetch node:", error);
return NextResponse.json(
{ error: "Failed to fetch node" },
{ status: 500 }
);
}
}
// PATCH update node
export async function PATCH(request: NextRequest, { params }: Params) {
try {
const { id } = await params;
const body = await request.json();
const node = await prisma.node.update({
where: { id },
data: body,
});
return NextResponse.json(node);
} catch (error) {
console.error("Failed to update node:", error);
return NextResponse.json(
{ error: "Failed to update node" },
{ status: 500 }
);
}
}
// DELETE node
export async function DELETE(request: NextRequest, { params }: Params) {
try {
const { id } = await params;
await prisma.node.delete({
where: { id },
});
return NextResponse.json({ success: true });
} catch (error) {
console.error("Failed to delete node:", error);
return NextResponse.json(
{ error: "Failed to delete node" },
{ status: 500 }
);
}
}