Work in Songs and Songbooks API
This commit is contained in:
1 parent
e1eaea0f17
commit
4bdf03426c
6 files changed
+291
-13
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { getSongs, searchSongsByTitle, createSong, } from "@/lib/db/song";
|
||||
|
||||
|
||||
@@ -30,6 +29,7 @@ export async function GET(request: Request) {
|
||||
return NextResponse.json(res.songBooks, { status: res.status });
|
||||
}
|
||||
|
||||
// Ansonsten alle Songs abrufen
|
||||
const res = await getSongs();
|
||||
|
||||
if (!res.success) {
|
||||
@@ -38,7 +38,7 @@ export async function GET(request: Request) {
|
||||
|
||||
return NextResponse.json(res.songs, { status: res.status });
|
||||
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
console.error("POST /api/songs error:", error);
|
||||
return NextResponse.json(
|
||||
{ message: "Internal Server Error" },
|
||||
@@ -97,7 +97,10 @@ export async function POST(request: Request) {
|
||||
const data = await request.json();
|
||||
|
||||
if (!data.title) {
|
||||
return NextResponse.json({ message: "Fields incomplete"}, { status: 400 });
|
||||
return NextResponse.json(
|
||||
{ message: "Field 'title' is required"},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const res = await createSong(data);
|
||||
@@ -110,6 +113,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
return NextResponse.json(res, { status: res.status });
|
||||
|
||||
} catch (error) {
|
||||
console.error("POST /api/songs error:", error);
|
||||
return NextResponse.json(
|
||||
@@ -117,4 +121,4 @@ export async function POST(request: Request) {
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user