// @wikiCategory: Liederbücher import { NextResponse } from "next/server"; import { getSongBooks, searchSongBooksByTitle, createSongBook } from "@/lib/db/songbook"; /** * @openapi * /api/songbooks: * get: * summary: Get all songbooks * responses: * 200: * description: List of songbooks * 500: * description: Internal Server Error * * @wikiDescription: Liste aller Liederbücher abrufen */ export async function GET(request: Request) { try { const { searchParams } = new URL(request.url); const query = searchParams.get("query") || searchParams.get("q"); // Wenn ein Suchbegriff übergeben wurde -> Sucheinbindung if (query) { const res = await searchSongBooksByTitle(query); // You can enter a limit if (!res.success) { return NextResponse.json({ message: res.error }, { status: res.status }); } return NextResponse.json(res.songBooks, { status: res.status }); } // Ansonsten alle Bücher abrufen const res = await getSongBooks(); if (!res.success) { return NextResponse.json({ message: res.error }, { status: res.status }); } return NextResponse.json(res.songBooks, { status: res.status }); } catch (error) { console.error("GET /api/songbooks error:", error); return NextResponse.json( { message: "Internal Server Error" }, { status: 500 } ); } } /** * @openapi * /api/songbooks: * post: * summary: Creates a new songbook * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - title * properties: * title: * 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 title) * 409: * description: Conflict (title already exists) * 500: * description: Internal Server Error * * @wikiDescription: Neues Liederbuch erstellen */ export async function POST(request: Request) { try { const data = await request.json(); if (!data.title || !data.language) { return NextResponse.json( { message: "Field 'title' and 'language' are required" }, { status: 400 } ); } const res = await createSongBook(data); if (!res.success) { return NextResponse.json( { message: res.error }, { status: res.status } ); } return NextResponse.json(res, { status: res.status }); } catch (error) { console.error("POST /api/songbooks error:", error); return NextResponse.json( { message: "Internal Server Error" }, { status: 500 } ); } }