diff --git a/app/api/songs/attach/route.ts b/app/api/songs/attach/route.ts new file mode 100644 index 0000000..ea385b5 --- /dev/null +++ b/app/api/songs/attach/route.ts @@ -0,0 +1,40 @@ +import { NextResponse } from "next/server"; +import { attachSongToSongbook } from "@/lib/db/managing"; + +export async function POST(request: Request) { + try { + const body = await request.json(); + const { songId, songbookId, number } = body; + + if (!songId || !songbookId || !number) { + return NextResponse.json( + { error: "songId, songbookId und number sind erforderlich." }, + { status: 400 } + ); + } + + const result = await attachSongToSongbook( + Number(songId), + Number(songbookId), + String(number) + ); + + if (result.success) { + return NextResponse.json( + { message: "Lied erfolgreich verknüpft!" }, + { status: 200 } + ); + } else { + return NextResponse.json( + { error: "Fehler beim Verknüpfen in der Datenbank." }, + { status: 500 } + ); + } + } catch (error) { + console.error("API Error in /api/songs/attach:", error); + return NextResponse.json( + { error: "Ungültiges JSON oder Serverfehler." }, + { status: 500 } + ); + } +} \ No newline at end of file