import { NextResponse } from "next/server"; import { getSongBookById, updateSongBook, deleteSongBook } from "@/lib/db/songbook"; interface RouteParams { params: Promise<{ songBookId: string; }>; }; /** * @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 }: RouteParams) { try { const { songBookId } = await params; const res = await getSongBookById(parseInt(songBookId)); 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 }: RouteParams) { try { const { songBookId } = await params; const data = await request.json(); const res = await updateSongBook(parseInt(songBookId), 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 }: RouteParams) { try { const { songBookId } = await params; const res = await deleteSongBook(parseInt(songBookId)); 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 } ); } }