Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7ade96371 | ||
|
|
5a56245218 | ||
|
|
5d6d8f15f3 | ||
|
|
1d1976ed07 | ||
|
|
14b8a0c65f | ||
|
|
df9143e95c | ||
|
|
c234c28d15 | ||
|
|
87801c5b9b | ||
|
|
bdc864cf94 | ||
|
|
da4d67ea47 |
No files matched your search
@@ -46,4 +46,3 @@ songs.sqlite
|
|||||||
|
|
||||||
.gitignore
|
.gitignore
|
||||||
/lib/generated/prisma
|
/lib/generated/prisma
|
||||||
pnpm-lock.yaml
|
|
||||||
+2
-2
@@ -11,13 +11,13 @@ COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
|
|||||||
RUN apk add --no-cache python3 make g++
|
RUN apk add --no-cache python3 make g++
|
||||||
|
|
||||||
# Installation mit deiner funktionierenden Workspace-Konfiguration
|
# Installation mit deiner funktionierenden Workspace-Konfiguration
|
||||||
RUN pnpm i --frozen-lockfile
|
RUN npm i --frozen-lockfile
|
||||||
|
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN pnpm run build
|
RUN npm run openapi:generate; npm run build
|
||||||
|
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { error } from "console";
|
import { error } from "console";
|
||||||
import Papa from "papaparse";
|
import Papa from "papaparse";
|
||||||
|
import { addSongToSongbook } from "@/lib/db/managing";
|
||||||
|
|
||||||
interface CSVRow {
|
interface CSVRow {
|
||||||
nummer: string;
|
nummer: string;
|
||||||
@@ -30,8 +31,8 @@ export async function uploadCSVAction(formData:FormData) {
|
|||||||
|
|
||||||
console.log("Data:", rows);
|
console.log("Data:", rows);
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
console.log(`Nummer: ${row.nummer}, Titel: ${row.titel}`);
|
//console.log(`Nummer: ${row.number}, Titel: ${row.titel}`);
|
||||||
//addSongToSongbook(String(row.titel), Number(songbookId), String(row.nummer))
|
addSongToSongbook(String(row.titel), Number(songbookId), String(row.nummer))
|
||||||
});
|
});
|
||||||
|
|
||||||
return { success: true, message: `${rows.length} Zeilen erfolgreich importiert.`};
|
return { success: true, message: `${rows.length} Zeilen erfolgreich importiert.`};
|
||||||
|
|||||||
+31
-42
@@ -9,7 +9,7 @@ import { Screens } from "@/components/DatabaseOverview";
|
|||||||
|
|
||||||
interface Songbook {
|
interface Songbook {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
name: string;
|
||||||
language: string;
|
language: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ interface Song {
|
|||||||
|
|
||||||
interface SongInfo {
|
interface SongInfo {
|
||||||
songbook_id: number;
|
songbook_id: number;
|
||||||
songbook_title: string;
|
songbook_name: string;
|
||||||
song_number: string;
|
song_number: string;
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ export default function AdminPage() {
|
|||||||
const [number, setNumber] = useState("");
|
const [number, setNumber] = useState("");
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
|
|
||||||
const [newBookTitle, setNewBookTitle] = useState("");
|
const [newBookName, setNewBookName] = useState("");
|
||||||
const [newBookLanguage, setNewBookLanguage] = useState("");
|
const [newBookLanguage, setNewBookLanguage] = useState("");
|
||||||
|
|
||||||
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
||||||
@@ -96,34 +96,21 @@ export default function AdminPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create song
|
const res = await fetch("/api/songs", {
|
||||||
const res1 = await fetch("/api/songs", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
songbookId: Number(selectedSongbookId),
|
||||||
|
number: number,
|
||||||
title: title
|
title: title
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
if (res1.ok) {
|
if (res.ok) {
|
||||||
console.log("Lied erfolgreich erstellt!");
|
alert("Lied erfolgreich hinzugefügt!");
|
||||||
|
setNumber("");
|
||||||
|
setTitle("");
|
||||||
} else {
|
} else {
|
||||||
console.log("Lied erstellen fehlgeschlagen!");
|
alert("Fehler beim Senden.");
|
||||||
}
|
|
||||||
|
|
||||||
// Attach song to songbook
|
|
||||||
const data = await res1.json()
|
|
||||||
const songId = data.song.id;
|
|
||||||
const res2 = await fetch(`/api/songbooks/${Number(selectedSongbookId)}/songs/${songId}`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
number: number
|
|
||||||
})
|
|
||||||
})
|
|
||||||
if (res2.ok) {
|
|
||||||
console.log("Lied erfolgreich dem Liederbuch zugewiesen!");
|
|
||||||
} else {
|
|
||||||
console.log("Fehler");
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed sending current songID:", error);
|
console.error("Failed sending current songID:", error);
|
||||||
@@ -137,17 +124,19 @@ export default function AdminPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res2 = await fetch(`/api/songbooks/${Number(selectedSongbookId)}/songs/${selectedSong.song_id}`, {
|
const res = await fetch("/api/songs/attach", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
number: number
|
songbookId: selectedSongbookId,
|
||||||
|
songId: selectedSong.song_id,
|
||||||
|
number: number,
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
if (res2.ok) {
|
if (res.ok) {
|
||||||
console.log("Lied erfolgreich dem Liederbuch zugewiesen!");
|
alert("Lied erfolgreich zum Liederbuch hinzugefügt!");
|
||||||
} else {
|
} else {
|
||||||
console.log("Fehler");
|
alert("Fehler beim Senden.");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed sending current songID:", error);
|
console.error("Failed sending current songID:", error);
|
||||||
@@ -180,8 +169,8 @@ export default function AdminPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const addSongbook = async () => {
|
const addSongbook = async () => {
|
||||||
if (!newBookTitle) {
|
if (!newBookName) {
|
||||||
alert("Der Title des Liederbuches darf nicht leer sein!");
|
alert("Der Name des Liederbuches darf nicht leer sein!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,14 +178,14 @@ export default function AdminPage() {
|
|||||||
const res = await fetch("/api/songbooks", {
|
const res = await fetch("/api/songbooks", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ title: newBookTitle, language: newBookLanguage })
|
body: JSON.stringify({ name: newBookName, language: newBookLanguage })
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const createdBook = await res.json();
|
const createdBook = await res.json();
|
||||||
setSongbooks([...songbooks, createdBook]);
|
setSongbooks([...songbooks, createdBook]);
|
||||||
alert("Liederbuch erfolgreich erstellt!");
|
alert("Liederbuch erfolgreich erstellt!");
|
||||||
setNewBookTitle("");
|
setNewBookName("");
|
||||||
setNewBookLanguage("");
|
setNewBookLanguage("");
|
||||||
} else {
|
} else {
|
||||||
alert("Failed adding songbook!");
|
alert("Failed adding songbook!");
|
||||||
@@ -226,8 +215,8 @@ export default function AdminPage() {
|
|||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="z.B. Gesangbuch"
|
placeholder="z.B. Gesangbuch"
|
||||||
value={newBookTitle}
|
value={newBookName}
|
||||||
onChange={(e) => setNewBookTitle(e.target.value)}
|
onChange={(e) => setNewBookName(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -259,7 +248,7 @@ export default function AdminPage() {
|
|||||||
<option value="">-- Bitte wählen --</option>
|
<option value="">-- Bitte wählen --</option>
|
||||||
{songbooks.map((book) => (
|
{songbooks.map((book) => (
|
||||||
<option key={book.id} value={String(book.id)}>
|
<option key={book.id} value={String(book.id)}>
|
||||||
{book.title}{book.language ? ` (${book.language})` : ""}
|
{book.name}{book.language ? ` (${book.language})` : ""}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</Input.Select>
|
</Input.Select>
|
||||||
@@ -301,7 +290,7 @@ export default function AdminPage() {
|
|||||||
<option value="">-- Bitte wählen --</option>
|
<option value="">-- Bitte wählen --</option>
|
||||||
{songbooks.map((book) => (
|
{songbooks.map((book) => (
|
||||||
<option key={book.id} value={String(book.id)}>
|
<option key={book.id} value={String(book.id)}>
|
||||||
{book.title}{book.language ? ` (${book.language})` : ""}
|
{book.name}{book.language ? ` (${book.language})` : ""}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</Input.Select>
|
</Input.Select>
|
||||||
@@ -346,7 +335,7 @@ export default function AdminPage() {
|
|||||||
<ul className="list-disc list-inside pl-2 text-xs text-neutral-400">
|
<ul className="list-disc list-inside pl-2 text-xs text-neutral-400">
|
||||||
{songInfos.map((info) => (
|
{songInfos.map((info) => (
|
||||||
<li key={info.songbook_id}>
|
<li key={info.songbook_id}>
|
||||||
{info.songbook_title} (Nr. {info.song_number})
|
{info.songbook_name} (Nr. {info.song_number})
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -367,7 +356,7 @@ export default function AdminPage() {
|
|||||||
<option value="">-- Bitte wählen --</option>
|
<option value="">-- Bitte wählen --</option>
|
||||||
{songbooks.map((book) => (
|
{songbooks.map((book) => (
|
||||||
<option key={book.id} value={String(book.id)}>
|
<option key={book.id} value={String(book.id)}>
|
||||||
{book.title}{book.language ? ` (${book.language})` : ""}
|
{book.name}{book.language ? ` (${book.language})` : ""}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</Input.Select>
|
</Input.Select>
|
||||||
@@ -401,7 +390,7 @@ export default function AdminPage() {
|
|||||||
{songInfos.length > 0 ? (
|
{songInfos.length > 0 ? (
|
||||||
songInfos.map((info) => (
|
songInfos.map((info) => (
|
||||||
<option key={info.songbook_id} value={String(info.songbook_id)}>
|
<option key={info.songbook_id} value={String(info.songbook_id)}>
|
||||||
{info.songbook_title} (Nr. {info.song_number})
|
{info.songbook_name} (Nr. {info.song_number})
|
||||||
</option>
|
</option>
|
||||||
))
|
))
|
||||||
): ""}
|
): ""}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// @/app/api/docs/api/routes.ts
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /api/docs/api:
|
||||||
|
* get:
|
||||||
|
* summary: OpenAPI-Spezifikation abrufen
|
||||||
|
* tags:
|
||||||
|
* - Docs
|
||||||
|
* description: Gibt die vollständige OpenAPI-JSON-Spezifikation der API zurück.
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Erfolgreich generierte OpenAPI-Spezifikation.
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
*/
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import spec from '@/src/generated/openapi.json';
|
||||||
|
|
||||||
|
export function GET() {
|
||||||
|
return NextResponse.json(spec);
|
||||||
|
}
|
||||||
@@ -1,40 +1,60 @@
|
|||||||
|
// @/app/api/songbooks/[songBookId]/route.ts
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongBookById, updateSongBook, deleteSongBook } from "@/lib/db/songbook";
|
import { getSongBookById, updateSongBook, deleteSongBook } from "@/lib/db/songbook";
|
||||||
// import { parseInt } from "@/lib/helper/checkvar";
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songBookId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songbooks/{id}:
|
* /api/songbooks/{songBookId}:
|
||||||
* get:
|
* get:
|
||||||
* summary: Einzelnen Songbook abrufen
|
* summary: Einzelnes Songbook abrufen
|
||||||
* tags:
|
* tags:
|
||||||
* - Songbooks
|
* - Songbooks
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: id
|
* name: songBookId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songbooks
|
* description: Die ID des Songbooks
|
||||||
|
* example: 1
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Songbook erfolgreich gefunden
|
* description: Songbook erfolgreich gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/SongBook'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Songbook-ID
|
* description: Ungültige Songbook-ID
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Songbook nicht gefunden
|
* description: Songbook nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
|
export async function GET(_request: Request, { params }: RouteParams) {
|
||||||
|
|
||||||
export async function GET(request: Request, { params }) {
|
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
|
|
||||||
|
const res = await getSongBookById(parseInt(songBookId));
|
||||||
const res = await getSongBookById(songBookId);
|
|
||||||
|
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -53,39 +73,63 @@ export async function GET(request: Request, { params }) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songbooks/{id}:
|
* /api/songbooks/{songBookId}:
|
||||||
* patch:
|
* patch:
|
||||||
* summary: Songbook aktualisieren
|
* summary: Songbook aktualisieren
|
||||||
* tags:
|
* tags:
|
||||||
* - Songbooks
|
* - Songbooks
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: id
|
* name: songBookId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songbooks
|
* description: Die ID des Songbooks
|
||||||
|
* example: 1
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* title:
|
||||||
|
* type: string
|
||||||
|
* example: "Feiert Jesus 1"
|
||||||
|
* language:
|
||||||
|
* type: string
|
||||||
|
* example: "DE"
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Songbook erfolgreich aktualisiert
|
* description: Songbook erfolgreich aktualisiert
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/SongBook'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Parameter oder Daten
|
* description: Ungültige Parameter oder Daten
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Songbook nicht gefunden
|
* description: Songbook nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }) {
|
export async function PATCH(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSongBook(songBookId, data);
|
const res = await updateSongBook(parseInt(songBookId), data);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -95,7 +139,7 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("API Error:", error);
|
console.error("API Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Fehler beim Laden der Songbookinfos" },
|
{ error: "Fehler beim Aktualisieren des Songbooks" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -104,32 +148,49 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songbooks/{id}:
|
* /api/songbooks/{songBookId}:
|
||||||
* delete:
|
* delete:
|
||||||
* summary: Songbook löschen
|
* summary: Songbook löschen
|
||||||
* tags:
|
* tags:
|
||||||
* - Songbooks
|
* - Songbooks
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: id
|
* name: songBookId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songbooks
|
* description: Die ID des Songbooks
|
||||||
|
* example: 1
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Songbook erfolgreich gelöscht
|
* description: Songbook erfolgreich gelöscht (gibt das gelöschte Songbook zurück)
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/SongBook'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Songbook-ID
|
* description: Ungültige Songbook-ID
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Songbook nicht gefunden
|
* description: Songbook nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function DELETE(request: Request, { params }) {
|
export async function DELETE(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const res = await deleteSongBook(songBookId);
|
const res = await deleteSongBook(parseInt(songBookId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -139,7 +200,7 @@ export async function DELETE(request: Request, { params }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("API Error:", error);
|
console.error("API Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Fehler beim Laden der Songbookinfos" },
|
{ error: "Fehler beim Löschen des Songbooks" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
|
// @/app/api/songbooks/[songBookId]/songs/[songId]/route.ts
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/songbooksongs";
|
import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/songbooksongs";
|
||||||
// import { parseInt } from "@/lib/helper/checkvar";
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songBookId: string;
|
||||||
|
songId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
@@ -8,7 +16,7 @@ import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/so
|
|||||||
* post:
|
* post:
|
||||||
* summary: Song zu Liederbuch hinzufügen
|
* summary: Song zu Liederbuch hinzufügen
|
||||||
* tags:
|
* tags:
|
||||||
* - Songbook
|
* - Songbooks
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: songBookId
|
* name: songBookId
|
||||||
@@ -16,12 +24,14 @@ import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/so
|
|||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Liederbuchs
|
* description: Die ID des Liederbuchs
|
||||||
|
* example: 1
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: songId
|
* name: songId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songs
|
* description: Die ID des Songs
|
||||||
|
* example: 1
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
* content:
|
* content:
|
||||||
@@ -38,20 +48,36 @@ import { addSongToBook, updateSongInBook, removeSongFromBook } from "@/lib/db/so
|
|||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Song erfolgreich zugewiesen
|
* description: Song erfolgreich zugewiesen
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/SongBookEntry'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Parameter oder fehlende Songnummer
|
* description: Ungültige Parameter oder fehlende Songnummer
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 409:
|
* 409:
|
||||||
* description: Songnummer bereits vergeben oder Song existiert bereits im Buch
|
* description: Songnummer bereits vergeben oder Song existiert bereits im Buch
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function POST(request: Request, { params }) {
|
export async function POST(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId, songId } = await params;
|
const { songBookId, songId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
|
|
||||||
|
|
||||||
const res = await addSongToBook(songId, songBookId, data.number);
|
const res = await addSongToBook(parseInt(songId), parseInt(songBookId), String(data.number));
|
||||||
|
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
@@ -62,7 +88,7 @@ export async function POST(request: Request, { params }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("API Error:", error);
|
console.error("API Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Fehler beim Laden der Songbookinfos" },
|
{ error: "Fehler beim Zuweisen des Songs" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -75,7 +101,7 @@ export async function POST(request: Request, { params }) {
|
|||||||
* patch:
|
* patch:
|
||||||
* summary: Songnummer eines Songs im Liederbuch aktualisieren
|
* summary: Songnummer eines Songs im Liederbuch aktualisieren
|
||||||
* tags:
|
* tags:
|
||||||
* - Songbook
|
* - Songbooks
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: songBookId
|
* name: songBookId
|
||||||
@@ -83,12 +109,14 @@ export async function POST(request: Request, { params }) {
|
|||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Liederbuchs
|
* description: Die ID des Liederbuchs
|
||||||
|
* example: 1
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: songId
|
* name: songId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songs
|
* description: Die ID des Songs
|
||||||
|
* example: 1
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
* content:
|
* content:
|
||||||
@@ -105,20 +133,40 @@ export async function POST(request: Request, { params }) {
|
|||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Songnummer erfolgreich aktualisiert
|
* description: Songnummer erfolgreich aktualisiert
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/SongBookEntry'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Parameter oder fehlende Daten
|
* description: Ungültige Parameter oder fehlende Daten
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Zuweisung nicht gefunden
|
* description: Zuweisung nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 409:
|
* 409:
|
||||||
* description: Neue Songnummer bereits vergeben
|
* description: Neue Songnummer bereits vergeben
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }) {
|
export async function PATCH(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId, songId } = await params;
|
const { songBookId, songId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSongInBook(songId, songBookId, data);
|
const res = await updateSongInBook(parseInt(songId), parseInt(songBookId), data);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -128,7 +176,7 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("API Error:", error);
|
console.error("API Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Fehler beim Laden der Songbookinfos" },
|
{ error: "Fehler beim Aktualisieren der Songnummer" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -141,7 +189,7 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
* delete:
|
* delete:
|
||||||
* summary: Song aus Liederbuch entfernen
|
* summary: Song aus Liederbuch entfernen
|
||||||
* tags:
|
* tags:
|
||||||
* - Songbook
|
* - Songbooks
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: songBookId
|
* name: songBookId
|
||||||
@@ -149,27 +197,45 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Liederbuchs
|
* description: Die ID des Liederbuchs
|
||||||
|
* example: 1
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: songId
|
* name: songId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songs
|
* description: Die ID des Songs
|
||||||
|
* example: 1
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Song erfolgreich aus dem Liederbuch entfernt
|
* description: Song erfolgreich aus dem Liederbuch entfernt (gibt die entfernte Zuweisung zurück)
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/SongBookEntry'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Parameter
|
* description: Ungültige Parameter
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Zuweisung nicht gefunden
|
* description: Zuweisung nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function DELETE(request: Request, { params }) {
|
export async function DELETE(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId, songId } = await params;
|
const { songBookId, songId } = await params;
|
||||||
|
|
||||||
const res = await removeSongFromBook(songId, songBookId);
|
const res = await removeSongFromBook(parseInt(songId), parseInt(songBookId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -179,7 +245,7 @@ export async function DELETE(request: Request, { params }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("API Error:", error);
|
console.error("API Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Fehler beim Laden der Songbookinfos" },
|
{ error: "Fehler beim Entfernen des Songs" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,77 @@
|
|||||||
|
// @/app/api/songbooks/[songBookId]/songs/route.ts
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongByNumber } from "@/lib/db/songbooksongs";
|
import { getSongByNumber } from "@/lib/db/songbooksongs";
|
||||||
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songBookId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songbooks/{id}/songs:
|
* /api/songbooks/{songBookId}/songs:
|
||||||
* get:
|
* get:
|
||||||
* summary: Einen Song nach Nummer in einem Songbook suchen
|
* summary: Einen Song nach Nummer in einem Songbook suchen
|
||||||
* tags:
|
* tags:
|
||||||
* - Songbook
|
* - Songbooks
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: id
|
* name: songBookId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songbooks
|
* description: Die ID des Songbooks
|
||||||
|
* example: 1
|
||||||
|
* - in: query
|
||||||
|
* name: number
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* description: Die Nummer des Songs im Songbook
|
||||||
|
* example: "123"
|
||||||
|
* - in: query
|
||||||
|
* name: n
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* description: Alias für `number`
|
||||||
|
* example: "123"
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Songbook erfolgreich gefunden
|
* description: Song im Songbook erfolgreich gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/SongBookEntry'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Songbook-ID
|
* description: Ungültige Songbook-ID oder fehlender number-Parameter
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Songbook nicht gefunden
|
* description: Songbook oder Song nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function GET(request: Request, { params }) {
|
export async function GET(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const number = searchParams.get("number") || searchParams.get("n");
|
const number = searchParams.get("number") || searchParams.get("n");
|
||||||
|
|
||||||
if(number){
|
if(number){
|
||||||
const res = await getSongByNumber(songBookId, number);
|
const res = await getSongByNumber(parseInt(songBookId), number);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
|
|||||||
+47
-21
@@ -1,22 +1,45 @@
|
|||||||
// @wikiCategory: Liederbücher
|
// @/app/api/songbooks/route.ts
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongBooks, searchSongBooksByTitle, createSongBook } from "@/lib/db/songbook";
|
import { getSongBooks, searchSongBooksByTitle, createSongBook } from "@/lib/db/songbook";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songbooks:
|
* /api/songbooks:
|
||||||
* get:
|
* get:
|
||||||
* summary: Get all songbooks
|
* summary: Get all songbooks or search songbooks by title
|
||||||
|
* tags:
|
||||||
|
* - Songbooks
|
||||||
|
* parameters:
|
||||||
|
* - in: query
|
||||||
|
* name: query
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* description: Search term for the songbook title
|
||||||
|
* example: "Feiert Jesus"
|
||||||
|
* - in: query
|
||||||
|
* name: q
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* description: Alias for `query`
|
||||||
|
* example: "Feiert Jesus"
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: List of songbooks
|
* description: List of songbooks (filtered by title if a query is given)
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* $ref: '#/components/schemas/SongBook'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Internal Server Error
|
* description: Internal Server Error
|
||||||
*
|
* content:
|
||||||
* @wikiDescription: Liste aller Liederbücher abrufen
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
@@ -60,6 +83,8 @@ export async function GET(request: Request) {
|
|||||||
* /api/songbooks:
|
* /api/songbooks:
|
||||||
* post:
|
* post:
|
||||||
* summary: Creates a new songbook
|
* summary: Creates a new songbook
|
||||||
|
* tags:
|
||||||
|
* - Songbooks
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
* content:
|
* content:
|
||||||
@@ -68,6 +93,7 @@ export async function GET(request: Request) {
|
|||||||
* type: object
|
* type: object
|
||||||
* required:
|
* required:
|
||||||
* - title
|
* - title
|
||||||
|
* - language
|
||||||
* properties:
|
* properties:
|
||||||
* title:
|
* title:
|
||||||
* type: string
|
* type: string
|
||||||
@@ -87,25 +113,25 @@ export async function GET(request: Request) {
|
|||||||
* type: boolean
|
* type: boolean
|
||||||
* example: true
|
* example: true
|
||||||
* songBook:
|
* songBook:
|
||||||
* type: object
|
* $ref: '#/components/schemas/SongBook'
|
||||||
* properties:
|
|
||||||
* id:
|
|
||||||
* type: integer
|
|
||||||
* example: 1
|
|
||||||
* title:
|
|
||||||
* type: string
|
|
||||||
* example: "Feiert Jesus 1"
|
|
||||||
* language:
|
|
||||||
* type: string
|
|
||||||
* example: "DE"
|
|
||||||
* 400:
|
* 400:
|
||||||
* description: Bad Request (missing title)
|
* description: Bad Request (missing title or language)
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 409:
|
* 409:
|
||||||
* description: Conflict (title already exists)
|
* description: Conflict (title already exists)
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Internal Server Error
|
* description: Internal Server Error
|
||||||
*
|
* content:
|
||||||
* @wikiDescription: Neues Liederbuch erstellen
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,36 +1,59 @@
|
|||||||
|
// @/app/api/songs/[songId]/route.ts
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongById, updateSong, deleteSong } from "@/lib/db/song";
|
import { getSongById, updateSong, deleteSong } from "@/lib/db/song";
|
||||||
// import { parseInt } from "@/lib/helper/checkvar";
|
|
||||||
|
|
||||||
|
interface RouteParams {
|
||||||
|
params: Promise<{
|
||||||
|
songId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songs/{id}:
|
* /api/songs/{songId}:
|
||||||
* get:
|
* get:
|
||||||
* summary: Einzelnen Song abrufen
|
* summary: Einzelnen Song abrufen
|
||||||
* tags:
|
* tags:
|
||||||
* - Songs
|
* - Songs
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: id
|
* name: songId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songs
|
* description: Die ID des Songs
|
||||||
|
* example: 1
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Song erfolgreich gefunden
|
* description: Song erfolgreich gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Song'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Song-ID
|
* description: Ungültige Song-ID
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Song nicht gefunden
|
* description: Song nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function GET(request: Request, { params }) {
|
export async function GET(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const res = await getSongById(songId);
|
const res = await getSongById(parseInt(songId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -49,39 +72,60 @@ export async function GET(request: Request, { params }) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songs/{id}:
|
* /api/songs/{songId}:
|
||||||
* patch:
|
* patch:
|
||||||
* summary: Song aktualisieren
|
* summary: Song aktualisieren
|
||||||
* tags:
|
* tags:
|
||||||
* - Songs
|
* - Songs
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: id
|
* name: songId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songs
|
* description: Die ID des Songs
|
||||||
|
* example: 1
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* title:
|
||||||
|
* type: string
|
||||||
|
* example: "Großer Gott"
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Song erfolgreich aktualisiert
|
* description: Song erfolgreich aktualisiert
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Song'
|
||||||
* 400:
|
* 400:
|
||||||
* description: Ungültige Parameter oder Daten
|
* description: Ungültige Parameter oder Daten
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Song nicht gefunden
|
* description: Song nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }) {
|
export async function PATCH(request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSong(songId, data);
|
const res = await updateSong(parseInt(songId), data);
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -91,7 +135,7 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("API Error:", error);
|
console.error("API Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Fehler beim Laden der Songinfos" },
|
{ error: "Fehler beim Aktualisieren des Songs" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -100,32 +144,49 @@ export async function PATCH(request: Request, { params }) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songs/{id}:
|
* /api/songs/{songId}:
|
||||||
* delete:
|
* delete:
|
||||||
* summary: Song löschen
|
* summary: Song löschen
|
||||||
* tags:
|
* tags:
|
||||||
* - Songs
|
* - Songs
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: path
|
* - in: path
|
||||||
* name: id
|
* name: songId
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: Die ID des Songs
|
* description: Die ID des Songs
|
||||||
|
* example: 1
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 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:
|
* 400:
|
||||||
* description: Ungültige Song-ID
|
* description: Ungültige Song-ID
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 404:
|
* 404:
|
||||||
* description: Song nicht gefunden
|
* description: Song nicht gefunden
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function DELETE(request: Request, { params }) {
|
export async function DELETE(_request: Request, { params }: RouteParams) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const res = await deleteSong(songId);
|
const res = await deleteSong(parseInt(songId));
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json({ message: res.error }, { status: res.status });
|
return NextResponse.json({ message: res.error }, { status: res.status });
|
||||||
@@ -135,7 +196,7 @@ export async function DELETE(request: Request, { params }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("API Error:", error);
|
console.error("API Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Fehler beim Laden der Songinfos" },
|
{ error: "Fehler beim Löschen des Songs" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-27
@@ -1,27 +1,51 @@
|
|||||||
// @wikiCategory: Lieder
|
// @/app/api/songs/route.ts
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getSongs, searchSongsByTitle, createSong, } from "@/lib/db/song";
|
import { getSongs, searchSongsByTitle, createSong } from "@/lib/db/song";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songs:
|
* /api/songs:
|
||||||
* get:
|
* 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:
|
* responses:
|
||||||
* 200:
|
* 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:
|
* 500:
|
||||||
* description: Internal Server Error
|
* description: Internal Server Error
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const query = searchParams.get("query") || searchParams.get("q");
|
const query = searchParams.get("query") || searchParams.get("q");
|
||||||
|
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
const res = await searchSongsByTitle(query/*, 20*/); // You can enter a limit (default: 20)
|
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 });
|
return NextResponse.json(res.songs, { status: res.status });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("POST /api/songs error:", error);
|
console.error("GET /api/songs error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: "Internal Server Error" },
|
{ message: "Internal Server Error" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
@@ -50,12 +74,13 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @openapi
|
* @openapi
|
||||||
* /api/songs:
|
* /api/songs:
|
||||||
* post:
|
* post:
|
||||||
* summary: Creates a new song
|
* summary: Creates a new song
|
||||||
|
* tags:
|
||||||
|
* - Songs
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
* content:
|
* content:
|
||||||
@@ -63,14 +88,14 @@ export async function GET(request: Request) {
|
|||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* type: object
|
||||||
* required:
|
* required:
|
||||||
* - name
|
* - title
|
||||||
* properties:
|
* properties:
|
||||||
* name:
|
* title:
|
||||||
* type: string
|
* type: string
|
||||||
* example: "Großer Gott"
|
* example: "Großer Gott"
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: Songbook successfully created
|
* description: Song successfully created
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
@@ -79,21 +104,26 @@ export async function GET(request: Request) {
|
|||||||
* success:
|
* success:
|
||||||
* type: boolean
|
* type: boolean
|
||||||
* example: true
|
* example: true
|
||||||
* songBook:
|
* song:
|
||||||
* type: object
|
* $ref: '#/components/schemas/Song'
|
||||||
* properties:
|
|
||||||
* id:
|
|
||||||
* type: integer
|
|
||||||
* example: 1
|
|
||||||
* title:
|
|
||||||
* type: string
|
|
||||||
* example: "Großer Gott"
|
|
||||||
* 400:
|
* 400:
|
||||||
* description: Bad Request (missing name)
|
* description: Bad Request (missing title)
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 409:
|
* 409:
|
||||||
* description: Conflict (title already exists)
|
* description: Conflict (title already exists)
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
* 500:
|
* 500:
|
||||||
* description: Internal Server Error
|
* description: Internal Server Error
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/Error'
|
||||||
*/
|
*/
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
@@ -101,7 +131,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
if (!data.title) {
|
if (!data.title) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: "Field 'title' is required"},
|
{ message: "Field 'title' is required" },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -110,10 +140,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{ message: res.error },
|
||||||
message: res.error,
|
|
||||||
song: res.song
|
|
||||||
},
|
|
||||||
{ status: res.status }
|
{ status: res.status }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
// @wikiCategory: Stream
|
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
|
||||||
import { getSongById } from "@/lib/db/song";
|
|
||||||
|
|
||||||
let currentSong = {
|
|
||||||
songID: "",
|
|
||||||
songbook: "",
|
|
||||||
number: "",
|
|
||||||
title: ""
|
|
||||||
};
|
|
||||||
|
|
||||||
// @wikiDescription: Akutell gestreamtes Lied abrufen
|
|
||||||
export async function GET() {
|
|
||||||
return NextResponse.json(currentSong)
|
|
||||||
}
|
|
||||||
|
|
||||||
// @wikiDescription: Lied zum Streamen festlegen
|
|
||||||
export async function POST(request: Request) {
|
|
||||||
try {
|
|
||||||
const data = await request.json();
|
|
||||||
const { songID, songbookID } = data;
|
|
||||||
|
|
||||||
if (!songID || !songbookID) {
|
|
||||||
return NextResponse.json(
|
|
||||||
{ success: false, error: "Fields incomplete!" },
|
|
||||||
{ status: 400 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await getSongById(songID);
|
|
||||||
|
|
||||||
if (result.success && result.song) {
|
|
||||||
const song = result.song;
|
|
||||||
|
|
||||||
// looking for the songbook with matching ID
|
|
||||||
const matchedBook = song.songBooks.find(
|
|
||||||
(entry) => String(entry.book.id) === String(songbookID)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (matchedBook) {
|
|
||||||
currentSong = {
|
|
||||||
songID: String(song.id),
|
|
||||||
songbook: matchedBook.book.title,
|
|
||||||
number: String(matchedBook.songNumber),
|
|
||||||
title: song.title,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// song does exist but not in the given songbook
|
|
||||||
currentSong = {
|
|
||||||
songID: "",
|
|
||||||
songbook: "",
|
|
||||||
number: "",
|
|
||||||
title: "",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// song does not exist
|
|
||||||
currentSong = {
|
|
||||||
songID: "",
|
|
||||||
songbook: "",
|
|
||||||
number: "",
|
|
||||||
title: "",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Aktualisierter currentSong:", currentSong);
|
|
||||||
|
|
||||||
return NextResponse.json({ success: true, currentSong });
|
|
||||||
} catch (error) {
|
|
||||||
console.error("API POST Error:", error);
|
|
||||||
return NextResponse.json(
|
|
||||||
{ success: false, error: "Server-Fehler" },
|
|
||||||
{ status: 500 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
// @/app/api/stream/route.ts
|
||||||
|
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* components:
|
||||||
|
* schemas:
|
||||||
|
* StreamError:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* success:
|
||||||
|
* type: boolean
|
||||||
|
* example: false
|
||||||
|
* error:
|
||||||
|
* type: string
|
||||||
|
* example: "Fields incomplete!"
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
let currentSong = {
|
||||||
|
number: "",
|
||||||
|
song: "",
|
||||||
|
songbook: "",
|
||||||
|
};
|
||||||
|
const clients = new Set<ReadableStreamDefaultController>();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /api/stream:
|
||||||
|
* get:
|
||||||
|
* summary: Aktuell gestreamtes Lied abrufen (Server-Sent Events)
|
||||||
|
* description: Öffnet einen SSE-Stream. Beim Verbinden wird das aktuelle Lied gesendet (falls gesetzt), danach bei jeder Änderung ein neues Event.
|
||||||
|
* tags:
|
||||||
|
* - Stream
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Event-Stream mit dem aktuellen Lied
|
||||||
|
* content:
|
||||||
|
* text/event-stream:
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* example: 'data: {"number":"104a","song":"Großer Gott","songbook":"Feiert Jesus 1"}'
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
let controllerRef: ReadableStreamDefaultController;
|
||||||
|
|
||||||
|
const stream = new ReadableStream({
|
||||||
|
start(controller) {
|
||||||
|
controllerRef = controller;
|
||||||
|
clients.add(controller);
|
||||||
|
|
||||||
|
if (currentSong.song) {
|
||||||
|
controller.enqueue(`data: ${JSON.stringify(currentSong)}\n\n`);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
cancel() {
|
||||||
|
clients.delete(controllerRef);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return new NextResponse(stream, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/event-stream',
|
||||||
|
'Cache-Control': 'no-cache',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @openapi
|
||||||
|
* /api/stream:
|
||||||
|
* post:
|
||||||
|
* summary: Lied zum Streamen festlegen
|
||||||
|
* description: Setzt das aktuelle Lied und sendet es an alle verbundenen Stream-Clients.
|
||||||
|
* tags:
|
||||||
|
* - Stream
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* required:
|
||||||
|
* - song
|
||||||
|
* - songBook
|
||||||
|
* - number
|
||||||
|
* properties:
|
||||||
|
* song:
|
||||||
|
* type: string
|
||||||
|
* example: "Großer Gott"
|
||||||
|
* songBook:
|
||||||
|
* type: string
|
||||||
|
* example: "Feiert Jesus 1"
|
||||||
|
* number:
|
||||||
|
* type: string
|
||||||
|
* example: "104a"
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Lied gesetzt und an alle Clients gesendet
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* success:
|
||||||
|
* type: boolean
|
||||||
|
* example: true
|
||||||
|
* currentSong:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* number:
|
||||||
|
* type: string
|
||||||
|
* example: "104a"
|
||||||
|
* song:
|
||||||
|
* type: string
|
||||||
|
* example: "Großer Gott"
|
||||||
|
* songbook:
|
||||||
|
* type: string
|
||||||
|
* example: "Feiert Jesus 1"
|
||||||
|
* 400:
|
||||||
|
* description: Felder unvollständig
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/StreamError'
|
||||||
|
* 500:
|
||||||
|
* description: Serverfehler
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: '#/components/schemas/StreamError'
|
||||||
|
*/
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const data = await request.json();
|
||||||
|
const song = data.song?.trim() ?? null;
|
||||||
|
const songbook = data.songBook?.trim() ?? null;
|
||||||
|
const number = data.number?.trim() ?? null;
|
||||||
|
|
||||||
|
if (song == null || songbook == null || number == null) {
|
||||||
|
return NextResponse.json({ success: false, error: "Fields incomplete!" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSong = {
|
||||||
|
song,
|
||||||
|
songbook,
|
||||||
|
number
|
||||||
|
};
|
||||||
|
|
||||||
|
clients.forEach((controller) => {
|
||||||
|
controller.enqueue(`data: ${JSON.stringify(currentSong)}\n\n`);
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true , currentSong }, { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json({ success: false, error: "Server-Fehler" }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import SwaggerUI from 'swagger-ui-react';
|
||||||
|
import 'swagger-ui-react/swagger-ui.css';
|
||||||
|
|
||||||
|
export default function DocsPage() {
|
||||||
|
return <SwaggerUI url="/api/docs/api" />;
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import { getAllApis } from "@/lib/wiki";
|
|
||||||
import Article from '@/components/wiki/Article';
|
|
||||||
import { API } from '@/components/mdx-components';
|
|
||||||
|
|
||||||
export default async function Page() {
|
|
||||||
const allApis = await getAllApis();
|
|
||||||
|
|
||||||
// Gruppiert die APIs nach ihrer Kategorie
|
|
||||||
const groupedApis = Object.groupBy(allApis, (api) => api.category);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Article title="API-Endpunkte">
|
|
||||||
{Object.entries(groupedApis).map(([category, apis]) => (
|
|
||||||
<div key={category} className="mb-10">
|
|
||||||
{/* Kategorie-Überschrift wird nur EINMAL pro Kategorie gerendert */}
|
|
||||||
<h2 className="text-2xl font-bold text-white mt-10 mb-4 border-b border-zinc-800 pb-2">
|
|
||||||
{category}
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
{/* Routen innerhalb dieser Kategorie durchgehen */}
|
|
||||||
{apis?.map((api, index) => (
|
|
||||||
<div key={index} className="my-4">
|
|
||||||
{api.methods.map((method, mIndex) => (
|
|
||||||
<API route={api.route} method={method.method} key={mIndex}>
|
|
||||||
{method.description}
|
|
||||||
</API>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</Article>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState, useEffect, ComponentPropsWithoutRef } from "react";
|
import { useState, useEffect, ComponentPropsWithoutRef } from "react";
|
||||||
|
|
||||||
import Card from "./Card";
|
import Card from "./Card"
|
||||||
import { Input } from "./FormElements";
|
import { Input } from "./FormElements"
|
||||||
|
|
||||||
interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title" | "children"> {
|
interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title" | "children"> {
|
||||||
onSelectSong?: (song: Song) => void;
|
onSelectSong?: (song: Song) => void;
|
||||||
@@ -9,7 +9,7 @@ interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title"
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Song {
|
interface Song {
|
||||||
id: number;
|
song_id: number;
|
||||||
songbook_id: number;
|
songbook_id: number;
|
||||||
song_number: string;
|
song_number: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -17,42 +17,43 @@ interface Song {
|
|||||||
|
|
||||||
interface Songbook {
|
interface Songbook {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
name: string;
|
||||||
language: string;
|
language: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Songs({ actionName = "Auswählen", onSelectSong, className = "", ...props }: SongsProps) {
|
function Songs({ actionName, onSelectSong, className = "", ...props }: SongsProps) {
|
||||||
const [song_search_name, setSongSearchName] = useState("");
|
const [song_search_name, setSongSearchName] = useState("");
|
||||||
const [searchResults, setSearchResults] = useState<Song[]>([]);
|
const [searchResults, setSearchResults] = useState<Song[]>([]);
|
||||||
const [allSongs, setAllSongs] = useState<Song[]>([]);
|
const [allSongs, setAllSongs] = useState<Song[]>([]);
|
||||||
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
||||||
|
|
||||||
|
|
||||||
const search = (query: string) => {
|
const search = (query: string) => {
|
||||||
setSongSearchName(query);
|
setSongSearchName(query);
|
||||||
if (query.trim() !== "") {
|
if (query.trim() !== "") {
|
||||||
setSearchResults(
|
setSearchResults(
|
||||||
allSongs.filter((song) =>
|
allSongs.filter((song) =>
|
||||||
song.title.toLowerCase().includes(query.toLowerCase()) ||
|
song.title.toLowerCase().includes(query.toLowerCase()) ||
|
||||||
song.song_number.includes(query)
|
song.song_number.includes(query)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
setSearchResults(allSongs);
|
setSearchResults(allSongs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getSongslist = async () => {
|
const getSongslist = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/songs");
|
const res = await fetch("/api/songs");
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setAllSongs(data);
|
setAllSongs(data);
|
||||||
setSearchResults(data);
|
setSearchResults(data);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setAllSongs([]);
|
setAllSongs([]);
|
||||||
console.error("Failed fetching songslist!", error);
|
console.error("Failed fetching songslist!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,14 +61,13 @@ function Songs({ actionName = "Auswählen", onSelectSong, className = "", ...pro
|
|||||||
try {
|
try {
|
||||||
const res = await fetch("/api/songbooks");
|
const res = await fetch("/api/songbooks");
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setSongbooks(data);
|
setSongbooks(data);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Loading songbooks failed: ", error);
|
console.error("Loading songbooks failed: ", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadSongbooks();
|
loadSongbooks();
|
||||||
getSongslist();
|
getSongslist();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -80,66 +80,64 @@ function Songs({ actionName = "Auswählen", onSelectSong, className = "", ...pro
|
|||||||
>
|
>
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Nach Songtitel oder Nummer suchen..."
|
placeholder="Nach Songtitel oder Nummer suchen..."
|
||||||
value={song_search_name}
|
value={song_search_name}
|
||||||
onChange={(e) => search(e.target.value)}
|
onChange={(e) => search(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* TABELLE */}
|
{/* TABELLE */}
|
||||||
<div className="flex-1 min-h-0 overflow-auto border border-neutral-200 dark:border-neutral-800 rounded-lg bg-white dark:bg-black">
|
<div className="flex-1 min-h-0 overflow-auto border border-neutral-200 dark:border-neutral-800 rounded-lg bg-white dark:bg-black">
|
||||||
<table className="w-full text-left border-collapse text-sm">
|
<table className="w-full text-left border-collapse text-sm">
|
||||||
<thead className="bg-neutral-100 dark:bg-neutral-900 sticky top-0 border-b border-neutral-200 dark:border-neutral-800 z-10">
|
<thead className="bg-neutral-100 dark:bg-neutral-900 sticky top-0 border-b border-neutral-200 dark:border-neutral-800 z-10">
|
||||||
<tr>
|
<tr>
|
||||||
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider">Titel</th>
|
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider">Titel</th>
|
||||||
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider">Liederbuch</th>
|
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider">Liederbuch</th>
|
||||||
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider text-center">Nummer</th>
|
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider text-center">Nummer</th>
|
||||||
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider text-right">Aktion</th>
|
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider text-right">Aktion</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="divide-y divide-neutral-200 dark:divide-neutral-800">
|
<tbody className="divide-y divide-neutral-200 dark:divide-neutral-800">
|
||||||
{searchResults.length === 0 ? (
|
{searchResults.length === 0 ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={4} className="p-8 text-center text-neutral-400 dark:text-neutral-500">Keine Lieder gefunden</td>
|
<td colSpan={4} className="p-8 text-center text-neutral-400 dark:text-neutral-500">Keine Lieder gefunden</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : (
|
) : (
|
||||||
searchResults.map((song) => {
|
searchResults.map((song) => {
|
||||||
const songBook = songbooks.find((book) => book.id === song.songbook_id);
|
const songBook = songbooks.find((book) => book.id === song.songbook_id);
|
||||||
|
return (
|
||||||
return (
|
<tr key={`${song.songbook_id}-${song.song_id}`} className="hover:bg-neutral-100/60 dark:hover:bg-neutral-900/40 transition">
|
||||||
<tr key={`${song.songbook_id}-${song.id}`} className="hover:bg-neutral-100/60 dark:hover:bg-neutral-900/40 transition">
|
<td className="p-3 font-medium text-neutral-900 dark:text-white max-w-[180px] sm:max-w-none truncate">
|
||||||
<td className="p-3 font-medium text-neutral-900 dark:text-white max-w-[180px] sm:max-w-none truncate">
|
{song.title}
|
||||||
{song.title}
|
<span className="block text-xs text-neutral-500 dark:text-neutral-400 sm:hidden mt-0.5">
|
||||||
<span className="block text-xs text-neutral-500 dark:text-neutral-400 sm:hidden mt-0.5">
|
{songBook ? songBook.name : "Unbekannt"}
|
||||||
{songBook ? songBook.title : "Unbekannt"}
|
</span>
|
||||||
</span>
|
</td>
|
||||||
</td>
|
<td className="p-3 text-neutral-700 dark:text-neutral-300 hidden sm:table-cell">
|
||||||
<td className="p-3 text-neutral-700 dark:text-neutral-300 hidden sm:table-cell">
|
{songBook ? songBook.name : "Unbekannt"}
|
||||||
{songBook ? songBook.title : "Unbekannt"}
|
</td>
|
||||||
</td>
|
<td className="p-3 text-center font-mono text-blue-600 dark:text-blue-400 font-bold">
|
||||||
<td className="p-3 text-center font-mono text-blue-600 dark:text-blue-400 font-bold">
|
{song.song_number}
|
||||||
{song.song_number}
|
</td>
|
||||||
</td>
|
<td className="p-3 text-right">
|
||||||
<td className="p-3 text-right">
|
<Input.Button
|
||||||
<Input.Button
|
onClick={() => onSelectSong?.(song)}
|
||||||
onClick={() => onSelectSong?.(song)}
|
className="bg-white dark:bg-black hover:bg-blue-600 dark:hover:bg-blue-600 border border-neutral-300 dark:border-neutral-700 hover:border-blue-600 dark:hover:border-blue-500 hover:text-white font-medium rounded-md px-3 py-1.5 transition text-xs"
|
||||||
className="bg-white dark:bg-black hover:bg-blue-600 dark:hover:bg-blue-600 border border-neutral-300 dark:border-neutral-700 hover:border-blue-600 dark:hover:border-blue-500 hover:text-white font-medium rounded-md px-3 py-1.5 transition text-xs"
|
>
|
||||||
>
|
{actionName}
|
||||||
{actionName}
|
</Input.Button>
|
||||||
</Input.Button>
|
</td>
|
||||||
</td>
|
</tr>
|
||||||
</tr>
|
);
|
||||||
);
|
|
||||||
})
|
})
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Screens = {
|
export const Screens = {
|
||||||
Songs: Songs,
|
Songs: Songs,
|
||||||
};
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
export interface Song {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SongBook {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
language?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SongDetailed {
|
||||||
|
song: {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
songBooks?:{songNumber: number; book:SongBook}[]
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type APIResponse<T> =
|
||||||
|
| { success: true; status: number; data: T }
|
||||||
|
| { success: false; status: number; error: string };
|
||||||
|
|
||||||
|
export type GetSongsResponse = APIResponse<Song[]>;
|
||||||
|
export type GetSongDetailedResponse =
|
||||||
|
| {
|
||||||
|
success: true;
|
||||||
|
status: number;
|
||||||
|
song: SongDetailed
|
||||||
|
}
|
||||||
|
| { success: false; status: number; error: string };
|
||||||
|
|
||||||
|
export type GetSongsDelailedResponse =
|
||||||
|
| {
|
||||||
|
success: true;
|
||||||
|
status: number;
|
||||||
|
songs: SongDetailed[]
|
||||||
|
}
|
||||||
|
| { success: false; status: number; error: string };
|
||||||
|
|
||||||
|
export type CreateSongsResponse = APIResponse<Song>;
|
||||||
+15
-8
@@ -1,7 +1,14 @@
|
|||||||
import { prisma } from "@/lib/db/prisma";
|
import { prisma } from "@/lib/db/prisma";
|
||||||
import { parseInt } from "@/lib/helper/checkvar";
|
import { parseInt } from "@/lib/helper/checkvar";
|
||||||
|
import type * as API from "./response";
|
||||||
// For Error checking use this import: import { Prisma } from "@prisma/client";
|
// For Error checking use this import: import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
|
interface Response {
|
||||||
|
success: boolean;
|
||||||
|
status: number;
|
||||||
|
songs?: [];
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetSongs
|
* GetSongs
|
||||||
@@ -9,7 +16,7 @@ import { parseInt } from "@/lib/helper/checkvar";
|
|||||||
*
|
*
|
||||||
* @returns {"success": boolean, "status": number, "songs": [{"id":number, "title": string},...]}
|
* @returns {"success": boolean, "status": number, "songs": [{"id":number, "title": string},...]}
|
||||||
*/
|
*/
|
||||||
export async function getSongs() {
|
export async function getSongs(): Promise<API.GetSongsResponse> {
|
||||||
try{
|
try{
|
||||||
const songs = await prisma.song.findMany({
|
const songs = await prisma.song.findMany({
|
||||||
select: {
|
select: {
|
||||||
@@ -35,7 +42,7 @@ export async function getSongs() {
|
|||||||
* @param id - ID indicatin the song
|
* @param id - ID indicatin the song
|
||||||
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
||||||
*/
|
*/
|
||||||
export async function getSongById(rawId: number) {
|
export async function getSongById(rawId: number): Promise<API.GetSongDetailedResponse> {
|
||||||
try{
|
try{
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -78,13 +85,13 @@ export async function getSongById(rawId: number) {
|
|||||||
*
|
*
|
||||||
* @param query - The search term for the song title.
|
* @param query - The search term for the song title.
|
||||||
* @param limit - Max number of songs returned for performance (default: 20).
|
* @param limit - Max number of songs returned for performance (default: 20).
|
||||||
* @returns @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
||||||
*/
|
*/
|
||||||
export async function searchSongsByTitle(query: string, limit: number = 20) {
|
export async function searchSongsByTitle(query: string, limit: number = 20): Promise<API.GetSongsDelailedResponse> {
|
||||||
try {
|
try {
|
||||||
const cleanQuery = query.trim();
|
const cleanQuery = query.trim();
|
||||||
if (!cleanQuery) {
|
if (!cleanQuery) {
|
||||||
return { success: true, songBooks: [] };
|
return { success: true, status: 200, songs: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const songs = await prisma.song.findMany({
|
const songs = await prisma.song.findMany({
|
||||||
@@ -124,7 +131,7 @@ export async function searchSongsByTitle(query: string, limit: number = 20) {
|
|||||||
* @param data - object with title
|
* @param data - object with title
|
||||||
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string}}
|
* @returns {"success": boolean, "status": number, "song": {"id":number, "title": string}}
|
||||||
*/
|
*/
|
||||||
export async function createSong(data: { title: string }) {
|
export async function createSong(data: { title: string }): Promise<API.CreateSongsResponse> {
|
||||||
try{
|
try{
|
||||||
if(!data.title){
|
if(!data.title){
|
||||||
return { success: false, status: 400, error: "Field 'title' is required" };
|
return { success: false, status: 400, error: "Field 'title' is required" };
|
||||||
@@ -164,7 +171,7 @@ export async function createSong(data: { title: string }) {
|
|||||||
export async function updateSong(
|
export async function updateSong(
|
||||||
rawId: number,
|
rawId: number,
|
||||||
data: { title?: string }
|
data: { title?: string }
|
||||||
) {
|
): Promise<API.CreateSongsResponse> {
|
||||||
try {
|
try {
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -213,7 +220,7 @@ export async function updateSong(
|
|||||||
* @param id - ID indicatin the song
|
* @param id - ID indicatin the song
|
||||||
* @returns {"success": boolean, "status": number, "song": {"id": number, "title": string}}
|
* @returns {"success": boolean, "status": number, "song": {"id": number, "title": string}}
|
||||||
*/
|
*/
|
||||||
export async function deleteSong(rawId: number) {
|
export async function deleteSong(rawId: number): Promise<API.CreateSongsResponse> {
|
||||||
try {
|
try {
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
export function parseInt(rawInteger){
|
export function parseInt(rawInteger: number){
|
||||||
const integer = Number.parseInt(rawInteger);
|
const integer = Number.parseInt(rawInteger);
|
||||||
|
|
||||||
if (Number.isNaN(integer) || !Number.isInteger(integer)) {
|
if (Number.isNaN(integer) || !Number.isInteger(integer)) {
|
||||||
|
|||||||
-228
@@ -1,228 +0,0 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import matter from 'gray-matter';
|
|
||||||
import ts from 'typescript';
|
|
||||||
import { ApiRoute, ApiMethod } from '@/types/api';
|
|
||||||
|
|
||||||
export type WikiArticle = {
|
|
||||||
slug: string;
|
|
||||||
title: string;
|
|
||||||
rawContent: string;
|
|
||||||
updatedAt?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type WikiPage = {
|
|
||||||
title: string;
|
|
||||||
path: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const wikiDirectory = path.join(process.cwd(), "data/wiki/pages");
|
|
||||||
|
|
||||||
export async function getWikiPageBySlug(slug: string): Promise<WikiArticle | null> {
|
|
||||||
try {
|
|
||||||
const fullPath = path.join(wikiDirectory, `${slug}.mdx`);
|
|
||||||
const fileContents = fs.readFileSync(fullPath, "utf-8");
|
|
||||||
|
|
||||||
const { data, content } = matter(fileContents);
|
|
||||||
|
|
||||||
return {
|
|
||||||
slug,
|
|
||||||
rawContent: content,
|
|
||||||
title: data.title || 'Unbenannt',
|
|
||||||
updatedAt: data.updatedAt || null,
|
|
||||||
...data,
|
|
||||||
} as WikiArticle;
|
|
||||||
} catch (error) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Liest rekursiv alle Dateien aus einem Verzeichnis aus.
|
|
||||||
* @param dirPath - Der Startordner
|
|
||||||
* @param extension - Optionale Dateiendung zur Filterung (z. B. ".ts" oder "ts")
|
|
||||||
* @returns Array mit den Dateipfaden
|
|
||||||
*/
|
|
||||||
export function getAllFiles(dirPath: string, extension?: string): string[] {
|
|
||||||
if (!fs.existsSync(dirPath)) return [];
|
|
||||||
|
|
||||||
let results: string[] = [];
|
|
||||||
|
|
||||||
// optionales führendes Dot sicherstellen (z. B. aus "ts" wird ".ts")
|
|
||||||
const targetExt = extension && !extension.startsWith('.')
|
|
||||||
? `.${extension}`
|
|
||||||
: extension;
|
|
||||||
|
|
||||||
// withFileTypes: true spart zusätzliche fs.statSync Aufrufe
|
|
||||||
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
|
||||||
const fullPath = path.join(dirPath, entry.name);
|
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
results = results.concat(getAllFiles(fullPath, targetExt));
|
|
||||||
} else if (!targetExt || entry.name.endsWith(targetExt)) {
|
|
||||||
results.push(fullPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Liest die Kategorie aus der Datei aus (@wikiCategory) oder ermittelt sie aus dem Ordnernamen.
|
|
||||||
*/
|
|
||||||
export function filterCategory(
|
|
||||||
content: string,
|
|
||||||
filePath: string,
|
|
||||||
prefix: string = '@wikiCategory'
|
|
||||||
): string {
|
|
||||||
// 1. In Kommentaren nach @wikiCategory suchen
|
|
||||||
const lines = content.split('\n');
|
|
||||||
for (const line of lines) {
|
|
||||||
const cleaned = line.replace(/^\/\/\s*/, '').replace(/^\/\*\*?\s*/, '').replace(/\*\/$/, '').trim();
|
|
||||||
if (cleaned.startsWith(prefix)) {
|
|
||||||
let category = cleaned.slice(prefix.length).trim().replace(/^:\s*/, '');
|
|
||||||
if (category) return category;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Fallback: Ersten Ordnernamen unter app/api/ als Kategorie nutzen
|
|
||||||
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
||||||
const apiMatch = normalizedPath.match(/app\/api\/([^/]+)/);
|
|
||||||
if (apiMatch && apiMatch[1]) {
|
|
||||||
const folderName = apiMatch[1];
|
|
||||||
// Ersten Buchstaben großschreiben (z. B. "stream" -> "Stream")
|
|
||||||
return folderName.charAt(0).toUpperCase() + folderName.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'Allgemein';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parst TypeScript-Code via AST und extrahiert HTTP-Methoden sowie deren Kommentare.
|
|
||||||
*/
|
|
||||||
export function filterMethods(
|
|
||||||
content: string,
|
|
||||||
prefix: string = '@wikiDescription'
|
|
||||||
): ApiMethod[] {
|
|
||||||
const sourceFile = ts.createSourceFile(
|
|
||||||
'temp.ts',
|
|
||||||
content,
|
|
||||||
ts.ScriptTarget.Latest,
|
|
||||||
/* setParentNodes */ true
|
|
||||||
);
|
|
||||||
|
|
||||||
const methods: ApiMethod[] = [];
|
|
||||||
const validMethods = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
|
|
||||||
|
|
||||||
ts.forEachChild(sourceFile, (node) => {
|
|
||||||
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
||||||
const functionName = node.name.text;
|
|
||||||
|
|
||||||
if (validMethods.has(functionName)) {
|
|
||||||
let description = '';
|
|
||||||
|
|
||||||
const commentRanges = ts.getLeadingCommentRanges(content, node.pos);
|
|
||||||
|
|
||||||
if (commentRanges && commentRanges.length > 0) {
|
|
||||||
const lastCommentRange = commentRanges[commentRanges.length - 1];
|
|
||||||
const rawComment = content.substring(
|
|
||||||
lastCommentRange.pos,
|
|
||||||
lastCommentRange.end
|
|
||||||
);
|
|
||||||
|
|
||||||
const cleanedComment = rawComment
|
|
||||||
.replace(/^\/\/\s*/, '')
|
|
||||||
.replace(/^\/\*\*?\s*/, '')
|
|
||||||
.replace(/\*\/$/, '')
|
|
||||||
.split('\n')
|
|
||||||
.map((line) => line.replace(/^\s*\*\s?/, '').trim())
|
|
||||||
.join(' ')
|
|
||||||
.trim();
|
|
||||||
|
|
||||||
if (cleanedComment.startsWith(prefix)) {
|
|
||||||
let textAfterPrefix = cleanedComment.slice(prefix.length).trim();
|
|
||||||
textAfterPrefix = textAfterPrefix.replace(/^:\s*/, '');
|
|
||||||
description = textAfterPrefix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
methods.push({
|
|
||||||
method: functionName,
|
|
||||||
description: description || 'Keine Beschreibung vorhanden.',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return methods;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Liest alle API-Dateien dynamisch aus und wandelt sie in ApiRoute-Objekte um.
|
|
||||||
*/
|
|
||||||
export async function getAllApis(): Promise<ApiRoute[]> {
|
|
||||||
try {
|
|
||||||
const apiBasePath = path.join(process.cwd(), "app/api");
|
|
||||||
const allTsFiles = getAllFiles(apiBasePath, ".ts");
|
|
||||||
const routes: ApiRoute[] = [];
|
|
||||||
|
|
||||||
allTsFiles.forEach((filePath) => {
|
|
||||||
const fileContents = fs.readFileSync(filePath, "utf-8");
|
|
||||||
|
|
||||||
// 1. Methoden extrahieren
|
|
||||||
const methods = filterMethods(fileContents, "@wikiDescription");
|
|
||||||
|
|
||||||
// Nur Routen hinzufügen, die auch API-Methoden exportieren
|
|
||||||
if (methods.length > 0) {
|
|
||||||
// 2. Kategorie ermitteln
|
|
||||||
const category = filterCategory(fileContents, filePath, "@wikiCategory");
|
|
||||||
|
|
||||||
// 3. Route-Pfad automatisch aus dem Dateipfad generieren (app/api/stream/currentID/route.ts -> stream/currentID)
|
|
||||||
const relativePath = path.relative(apiBasePath, filePath).replace(/\\/g, '/');
|
|
||||||
const routePath = relativePath
|
|
||||||
.replace(/\/route\.ts$/, '')
|
|
||||||
.replace(/\.ts$/, '');
|
|
||||||
|
|
||||||
routes.push({
|
|
||||||
route: routePath,
|
|
||||||
category,
|
|
||||||
methods,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return routes;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Fehler beim Auslesen der API-Dateien:", error);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAllWikiPages(): Promise<WikiPage[]> {
|
|
||||||
try {
|
|
||||||
const pagesBasePath = path.join(process.cwd(), "data/wiki/pages");
|
|
||||||
const allPaths = getAllFiles(pagesBasePath, ".mdx");
|
|
||||||
const allPages: WikiPage[] = [];
|
|
||||||
|
|
||||||
for (const filePath of allPaths) {
|
|
||||||
// extract filename of the path (e. g. "test" at "data/wiki/pages/test.mdx")
|
|
||||||
const slug = path.parse(filePath).name;
|
|
||||||
|
|
||||||
const wikiPage = await getWikiPageBySlug(slug);
|
|
||||||
|
|
||||||
if (wikiPage) {
|
|
||||||
allPages.push({
|
|
||||||
path: slug,
|
|
||||||
title: wikiPage.title,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(allPages);
|
|
||||||
return allPages;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Fehler beim Auslesen der Wiki-Seiten:", error);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Generated
+8878
-1488
File diff suppressed because it is too large.
Load diff
+9
-8
@@ -7,23 +7,19 @@
|
|||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"postinstall": "prisma generate",
|
"openapi:generate": "node scripts/generate-openapi.mjs"
|
||||||
"predev": "prisma migrate deploy",
|
|
||||||
"prestart": "prisma migrate deploy",
|
|
||||||
"db:setup": "node -e \"require('fs').existsSync('.env')||require('fs').copyFileSync('example.env','.env')\" && prisma migrate deploy && prisma generate"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/adapter-better-sqlite3": "^7.9.1",
|
"@prisma/adapter-better-sqlite3": "^7.9.1",
|
||||||
"@prisma/client": "^7.9.1",
|
"@prisma/client": "^7.10.0",
|
||||||
"@types/papaparse": "^5.5.2",
|
"@types/papaparse": "^5.5.2",
|
||||||
"argon2": "^0.45.1",
|
"argon2": "^0.45.1",
|
||||||
"better-sqlite3": "^13.0.2",
|
"better-sqlite3": "^13.0.2",
|
||||||
"dotenv": "^17.4.2",
|
"dotenv": "^17.4.2",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"next": "16.2.9",
|
"next": "^16.4.0",
|
||||||
"next-mdx-remote": "^6.0.0",
|
"next-mdx-remote": "^6.0.0",
|
||||||
"papaparse": "^5.5.4",
|
"papaparse": "^5.5.4",
|
||||||
"prisma": "^7.9.1",
|
|
||||||
"react": "19.2.4",
|
"react": "19.2.4",
|
||||||
"react-dom": "19.2.4",
|
"react-dom": "19.2.4",
|
||||||
"rehype-autolink-headings": "^7.1.0",
|
"rehype-autolink-headings": "^7.1.0",
|
||||||
@@ -35,7 +31,8 @@
|
|||||||
"remark-html": "^16.0.1",
|
"remark-html": "^16.0.1",
|
||||||
"remark-parse": "^11.0.0",
|
"remark-parse": "^11.0.0",
|
||||||
"remark-rehype": "^11.1.2",
|
"remark-rehype": "^11.1.2",
|
||||||
"shiki": "^4.4.1"
|
"shiki": "^4.4.1",
|
||||||
|
"swagger-ui-react": "^5.33.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
@@ -44,8 +41,12 @@
|
|||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
|
"@types/swagger-jsdoc": "^6.0.4",
|
||||||
|
"@types/swagger-ui-react": "^5.18.0",
|
||||||
"eslint": "^9",
|
"eslint": "^9",
|
||||||
"eslint-config-next": "16.2.9",
|
"eslint-config-next": "16.2.9",
|
||||||
|
"prisma": "^8.0.0-rc.22",
|
||||||
|
"swagger-jsdoc": "^6.3.0",
|
||||||
"tailwindcss": "^4",
|
"tailwindcss": "^4",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import swaggerJsdoc from 'swagger-jsdoc';
|
||||||
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
||||||
|
import { dirname } from 'node:path';
|
||||||
|
|
||||||
|
const spec = swaggerJsdoc({
|
||||||
|
definition: {
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: { title: 'PsalmTafel API', version: '1.0.0' },
|
||||||
|
},
|
||||||
|
apis: ['./app/api/**/*.ts'],
|
||||||
|
failOnErrors: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const out = 'src/generated/openapi.json';
|
||||||
|
mkdirSync(dirname(out), { recursive: true });
|
||||||
|
writeFileSync(out, JSON.stringify(spec, null, 2));
|
||||||
|
|
||||||
|
console.log(`OpenAPI: ${Object.keys(spec.paths ?? {}).length} Pfade -> ${out}`);
|
||||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user