diff --git a/app/api/songs/remove/route.ts b/app/api/songs/remove/route.ts new file mode 100644 index 0000000..42745b6 --- /dev/null +++ b/app/api/songs/remove/route.ts @@ -0,0 +1,39 @@ +import { NextResponse } from "next/server"; +import { removeSongfromSongbook } from "@/lib/db/managing"; + +export async function POST(request: Request) { + try { + const body = await request.json(); + const { songId, songbookId } = body; + + if (isNaN(songId) || isNaN(songbookId)) { + return NextResponse.json( + { error: "Ungültige IDs." }, + { status: 400 } + ); + } + + const result = await removeSongfromSongbook( + Number(songId), + Number(songbookId) + ); + + if (result.success) { + return NextResponse.json( + { message: "Lied erfolgreich aus dem Liederbuch gelöscht!" }, + { status: 200 } + ); + } else { + return NextResponse.json( + { error: "Fehler beim Löschen aus dem Liederbuch." }, + { status: 500 } + ); + } + } catch (error) { + console.error("API Error in /api/songs/remove:", error); + return NextResponse.json( + { error: "Ungültiges JSON oder Serverfehler." }, + { status: 500 } + ); + } +} \ No newline at end of file