API work on SongbookSongs
This commit is contained in:
1 parent
4bdf03426c
commit
b060ab29cf
10 files changed
+347
-119
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getSongByNumber } from "@/lib/db/songbooksongs";
|
||||
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /api/songbooks/{id}/songs:
|
||||
* get:
|
||||
* summary: Einen Song nach Nummer in einem Songbook suchen
|
||||
* tags:
|
||||
* - Songbook
|
||||
* 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 { songBookId } = await params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const number = searchParams.get("number") || searchParams.get("n");
|
||||
|
||||
if(number){
|
||||
const res = await getSongByNumber(songBookId, number);
|
||||
|
||||
if (!res.success) {
|
||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||
}
|
||||
|
||||
return NextResponse.json(res.entry, { status: res.status });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Need a number query (number=123)" }, { status: 400 });
|
||||
} catch (error) {
|
||||
console.error("API Error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Fehler beim Laden der Songbookinfos" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user