API work on SongbookSongs

This commit is contained in:
Rudi committed 2026-08-27 14:59:19 +02:00
1 parent 4bdf03426c
commit b060ab29cf
10 files changed
+347 -119

No files matched your search

@@ -29,14 +29,14 @@ import { getSongById, updateSong, deleteSong } from "@/lib/db/song";
*/
export async function GET(request: Request, { params }) {
try {
const { id } = await params;
const res = await getSongById(id);
const { songId } = await params;
const res = await getSongById(songId);
if (!res.success) {
return NextResponse.json({ message: res.error }, { status: res.status });
}
return NextResponse.json({ message: res.error }, { status: res.status });
}
return NextResponse.json(res.song, { status: res.status });
return NextResponse.json(res.song, { status: res.status });
} catch (error) {
console.error("API Error:", error);
return NextResponse.json(
@@ -79,9 +79,9 @@ export async function GET(request: Request, { params }) {
*/
export async function PATCH(request: Request, { params }) {
try {
const { id } = await params;
const { songId } = await params;
const data = await request.json();
const res = await updateSong(id, data);
const res = await updateSong(songId, data);
if (!res.success) {
return NextResponse.json({ message: res.error }, { status: res.status });
@@ -124,8 +124,8 @@ export async function PATCH(request: Request, { params }) {
*/
export async function DELETE(request: Request, { params }) {
try {
const { id } = await params;
const res = await deleteSong(id);
const { songId } = await params;
const res = await deleteSong(songId);
if (!res.success) {
return NextResponse.json({ message: res.error }, { status: res.status });
-40
View File
@@ -1,40 +0,0 @@
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 }
);
}
}
-39
View File
@@ -1,39 +0,0 @@
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 }
);
}
}