Work in Songs and Songbooks API
This commit is contained in:
1 parent
e1eaea0f17
commit
4bdf03426c
6 files changed
+291
-13
No files matched your search
@@ -1,6 +1,141 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
getSongBookById,
|
||||
upateSongBook,
|
||||
deleteSongBook
|
||||
} from "@/lib/db/songbook";
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user