refactor: /api/songbooks

This commit is contained in:
rudi committed 2026-07-31 11:25:18 +02:00
1 parent 69378ca439
commit 9d8c7428e6
1 file changed
+77 -8
+77 -8
View File
@@ -24,7 +24,7 @@ export async function GET(request: Request) {
// Wenn ein Suchbegriff übergeben wurde -> Sucheinbindung
if (query) {
const res = await searchSongBookByTitle(query);
const res = await searchSongBookByTitle(query); // You can enter a limit
if (!res.success) {
return NextResponse.json({ message: res.error }, { status: 500 });
@@ -52,19 +52,88 @@ export async function GET(request: Request) {
}
/**
* @openapi
* /api/songbooks:
* post:
* summary: Creates a new songbook
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - name
* properties:
* name:
* type: string
* example: "Feiert Jesus 1"
* language:
* type: string
* example: "DE"
* responses:
* 201:
* description: Songbook successfully created
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* songBook:
* type: object
* properties:
* id:
* type: integer
* example: 1
* title:
* type: string
* example: "Feiert Jesus 1"
* language:
* type: string
* example: "DE"
* 400:
* description: Bad Request (missing name)
* 409:
* description: Conflict (title already exists)
* 500:
* description: Internal Server Error
*/
export async function POST(request: Request) {
try {
const { name, language } = await request.json();
const body = await request.json();
const name = body.name ? String(body.name).trim() : "";
const language = body.language ? String(body.language).trim() : "";
if (!name ) {
return NextResponse.json({ success: false, message: "Fields incomplete (name)"}, { status: 400 })
if (!name || !language) {
return NextResponse.json(
{ message: "Field 'name' and 'language' are required" },
{ status: 400 }
);
}
const newBook = await createSongBook({String(name), String(language)})
const res = await createSongBook({
title: name,
language: language,
});
if (!res.success) {
return NextResponse.json(
{ message: res.error },
{ status: res.status } // ALERT-TODO Implement!!!
);
}
return NextResponse.json(res, { status: 201 });
return NextResponse.json(newBook, { status: 201 })
} catch (error) {
return NextResponse.json({ success: false }, { status: 500 })
console.error("POST /api/songbooks error:", error);
return NextResponse.json(
{ message: "Internal Server Error" },
{ status: 500 }
);
}
}