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

+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 }
);
}