34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
import { getSongs, addSongToSongbook } from "@/lib/db/managing";
|
|
|
|
// @wikiDescription: Liste aller Lieder abrufen
|
|
export async function GET() {
|
|
const songs = await getSongs();
|
|
if (songs) {
|
|
return NextResponse.json(songs);
|
|
} else {
|
|
return NextResponse.json({ success: false}, { status: 500})
|
|
}
|
|
}
|
|
|
|
// @wikiDescription: Lied in einem Liederbuch erstellen
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const { title, songbookId, number } = await request.json();
|
|
|
|
if (!title || !songbookId || !number) {
|
|
return NextResponse.json({ success: false, message: "Fields incomplete"}, { status: 400 });
|
|
}
|
|
|
|
const result = await addSongToSongbook(title, Number(songbookId), String(number));
|
|
if (result.success) {
|
|
return NextResponse.json({ success: true });
|
|
} else {
|
|
return NextResponse.json({ success: false }, { status: 500 });
|
|
}
|
|
|
|
} catch (error) {
|
|
return NextResponse.json({ success: false }, { status: 500 });
|
|
}
|
|
} |