40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
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 (isNaN(songId) || isNaN(songbookId) || !number) {
|
|
return NextResponse.json(
|
|
{ error: "Ungültige IDs oder fehlende Nummer." },
|
|
{ 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 }
|
|
);
|
|
}
|
|
} |