Update API Doc

This commit is contained in:
Rudi committed 2026-10-13 19:26:56 +02:00
1 parent 5d6d8f15f3
commit 5a56245218
10 files changed
+1196 -229

No files matched your search

+66 -9
View File
@@ -1,3 +1,5 @@
// @/app/api/songs/[songId]/route.ts
import { NextResponse } from "next/server";
import { getSongById, updateSong, deleteSong } from "@/lib/db/song";
@@ -9,27 +11,44 @@ interface RouteParams {
/**
* @openapi
* /api/songs/{id}:
* /api/songs/{songId}:
* get:
* summary: Einzelnen Song abrufen
* tags:
* - Songs
* parameters:
* - in: path
* name: id
* name: songId
* required: true
* schema:
* type: integer
* description: Die ID des Songs
* example: 1
* responses:
* 200:
* description: Song erfolgreich gefunden
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Song'
* 400:
* description: Ungültige Song-ID
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 404:
* description: Song nicht gefunden
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 500:
* description: Serverfehler
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
export async function GET(_request: Request, { params }: RouteParams) {
try {
@@ -53,33 +72,54 @@ export async function GET(_request: Request, { params }: RouteParams) {
/**
* @openapi
* /api/songs/{id}:
* /api/songs/{songId}:
* patch:
* summary: Song aktualisieren
* tags:
* - Songs
* parameters:
* - in: path
* name: id
* name: songId
* required: true
* schema:
* type: integer
* description: Die ID des Songs
* example: 1
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* title:
* type: string
* example: "Großer Gott"
* responses:
* 200:
* description: Song erfolgreich aktualisiert
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Song'
* 400:
* description: Ungültige Parameter oder Daten
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 404:
* description: Song nicht gefunden
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 500:
* description: Serverfehler
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
export async function PATCH(request: Request, { params }: RouteParams) {
try {
@@ -95,7 +135,7 @@ export async function PATCH(request: Request, { params }: RouteParams) {
} catch (error) {
console.error("API Error:", error);
return NextResponse.json(
{ error: "Fehler beim Laden der Songinfos" },
{ error: "Fehler beim Aktualisieren des Songs" },
{ status: 500 }
);
}
@@ -104,27 +144,44 @@ export async function PATCH(request: Request, { params }: RouteParams) {
/**
* @openapi
* /api/songs/{id}:
* /api/songs/{songId}:
* delete:
* summary: Song löschen
* tags:
* - Songs
* parameters:
* - in: path
* name: id
* name: songId
* required: true
* schema:
* type: integer
* description: Die ID des Songs
* example: 1
* responses:
* 200:
* description: Song erfolgreich gelöscht
* description: Song erfolgreich gelöscht (gibt den gelöschten Song zurück)
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Song'
* 400:
* description: Ungültige Song-ID
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 404:
* description: Song nicht gefunden
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 500:
* description: Serverfehler
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
export async function DELETE(_request: Request, { params }: RouteParams) {
try {
@@ -139,7 +196,7 @@ export async function DELETE(_request: Request, { params }: RouteParams) {
} catch (error) {
console.error("API Error:", error);
return NextResponse.json(
{ error: "Fehler beim Laden der Songinfos" },
{ error: "Fehler beim Löschen des Songs" },
{ status: 500 }
);
}
+53 -23
View File
@@ -1,27 +1,51 @@
// @wikiCategory: Lieder
// @/app/api/songs/route.ts
import { NextResponse } from "next/server";
import { getSongs, searchSongsByTitle, createSong, } from "@/lib/db/song";
import { getSongs, searchSongsByTitle, createSong } from "@/lib/db/song";
/**
* @openapi
* /api/songs:
* get:
* summary: Get all songs
* summary: Get all songs or search songs by title
* tags:
* - Songs
* parameters:
* - in: query
* name: query
* required: false
* schema:
* type: string
* description: Search term for the song title
* example: "Großer Gott"
* - in: query
* name: q
* required: false
* schema:
* type: string
* description: Alias for `query`
* example: "Großer Gott"
* responses:
* 200:
* description: List of songs
* description: List of songs (filtered by title if a query is given)
* content:
* application/json:
* schema:
* type: array
* items:
* $ref: '#/components/schemas/Song'
* 500:
* description: Internal Server Error
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const query = searchParams.get("query") || searchParams.get("q");
if (query) {
const res = await searchSongsByTitle(query/*, 20*/); // You can enter a limit (default: 20)
@@ -42,7 +66,7 @@ export async function GET(request: Request) {
return NextResponse.json(res.songs, { status: res.status });
} catch (error) {
console.error("POST /api/songs error:", error);
console.error("GET /api/songs error:", error);
return NextResponse.json(
{ message: "Internal Server Error" },
{ status: 500 }
@@ -50,12 +74,13 @@ export async function GET(request: Request) {
}
}
/**
* @openapi
* /api/songs:
* post:
* summary: Creates a new song
* tags:
* - Songs
* requestBody:
* required: true
* content:
@@ -63,14 +88,14 @@ export async function GET(request: Request) {
* schema:
* type: object
* required:
* - name
* - title
* properties:
* name:
* title:
* type: string
* example: "Großer Gott"
* responses:
* 201:
* description: Songbook successfully created
* description: Song successfully created
* content:
* application/json:
* schema:
@@ -79,21 +104,26 @@ export async function GET(request: Request) {
* success:
* type: boolean
* example: true
* songBook:
* type: object
* properties:
* id:
* type: integer
* example: 1
* title:
* type: string
* example: "Großer Gott"
* song:
* $ref: '#/components/schemas/Song'
* 400:
* description: Bad Request (missing name)
* description: Bad Request (missing title)
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 409:
* description: Conflict (title already exists)
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 500:
* description: Internal Server Error
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
export async function POST(request: Request) {
try {
@@ -101,7 +131,7 @@ export async function POST(request: Request) {
if (!data.title) {
return NextResponse.json(
{ message: "Field 'title' is required"},
{ message: "Field 'title' is required" },
{ status: 400 }
);
}