import { NextResponse } from "next/server"; import { getSongBookById, upateSongBook, deleteSongBook } from "@/lib/db/songbook"; // import { parseInt } from "@/lib/helper/checkvar"; /** * @openapi * /api/songbooks/{id}: * get: * summary: Einzelnen Songbook abrufen * tags: * - Songbooks * parameters: * - in: path * name: id * required: true * schema: * type: integer * description: Die ID des Songbooks * responses: * 200: * description: Songbook erfolgreich gefunden * 400: * description: Ungültige Songbook-ID * 404: * description: Songbook nicht gefunden * 500: * description: Serverfehler */ export async function GET(request: Request, { params }) { try { const { id } = await params; const res = await getSongBookById(id); if (!res.success) { return NextResponse.json({ message: res.error }, { status: res.status }); } return NextResponse.json(res.songBook, { status: res.status }); } catch (error) { console.error("API Error:", error); return NextResponse.json( { error: "Fehler beim Laden der Songbookinfos" }, { status: 500 } ); } } /** * @openapi * /api/songbooks/{id}: * patch: * summary: Songbook aktualisieren * tags: * - Songbooks * parameters: * - in: path * name: id * required: true * schema: * type: integer * description: Die ID des Songbooks * requestBody: * required: true * content: * application/json: * schema: * type: object * responses: * 200: * description: Songbook erfolgreich aktualisiert * 400: * description: Ungültige Parameter oder Daten * 404: * description: Songbook nicht gefunden * 500: * description: Serverfehler */ export async function PATCH(request: Request, { params }) { try { const { id } = await params; const data = await request.json(); const res = await upateSongBook(id, data); if (!res.success) { return NextResponse.json({ message: res.error }, { status: res.status }); } return NextResponse.json(res.songBook, { status: res.status }); } catch (error) { console.error("API Error:", error); return NextResponse.json( { error: "Fehler beim Laden der Songbookinfos" }, { status: 500 } ); } } /** * @openapi * /api/songbooks/{id}: * delete: * summary: Songbook löschen * tags: * - Songbooks * parameters: * - in: path * name: id * required: true * schema: * type: integer * description: Die ID des Songbooks * responses: * 200: * description: Songbook erfolgreich gelöscht * 400: * description: Ungültige Songbook-ID * 404: * description: Songbook nicht gefunden * 500: * description: Serverfehler */ export async function DELETE(request: Request, { params }) { try { const { id } = await params; const res = await deleteSongBook(id); if (!res.success) { return NextResponse.json({ message: res.error }, { status: res.status }); } return NextResponse.json(res.songBook, { status: res.status }); } catch (error) { console.error("API Error:", error); return NextResponse.json( { error: "Fehler beim Laden der Songbookinfos" }, { status: 500 } ); } }