feat: add api for removeSongFromSongbook
This commit is contained in:
1 parent
57ea3907b6
commit
dc75753f41
1 file changed
+39
@@ -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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user