Feat/admin options #14
@@ -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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user