From 130e282cd6895a69e1b5a46e1801d09ccba6a848 Mon Sep 17 00:00:00 2001 From: headlessdev Date: Mon, 14 Apr 2025 12:46:05 +0200 Subject: [PATCH] Edit Application API Route --- app/api/applications/edit/route.ts | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app/api/applications/edit/route.ts diff --git a/app/api/applications/edit/route.ts b/app/api/applications/edit/route.ts new file mode 100644 index 0000000..3637fa3 --- /dev/null +++ b/app/api/applications/edit/route.ts @@ -0,0 +1,38 @@ +import { NextResponse, NextRequest } from "next/server"; +import { prisma } from "@/lib/prisma"; + +interface EditRequest { + id: number; + name: string; + description: string; + icon: string; + publicURL: string; + localURL: string; +} + +export async function PUT(request: NextRequest) { + try { + const body: EditRequest = await request.json(); + const { id, name, description, icon, publicURL, localURL } = body; + + const existingServer = await prisma.server.findUnique({ where: { id } }); + if (!existingServer) { + return NextResponse.json({ error: "Server not found" }, { status: 404 }); + } + + const updatedApplication = await prisma.application.update({ + where: { id }, + data: { + name, + description, + icon, + publicURL, + localURL + } + }); + + return NextResponse.json({ message: "Application updated", application: updatedApplication }); + } catch (error: any) { + return NextResponse.json({ error: error.message }, { status: 500 }); + } +} \ No newline at end of file