Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edd33ab712 | ||
|
|
fde1f27745 | ||
|
|
583ef90a7b | ||
|
|
2fb484ad26 |
No files matched your search
@@ -46,3 +46,4 @@ songs.sqlite
|
|||||||
|
|
||||||
.gitignore
|
.gitignore
|
||||||
/lib/generated/prisma
|
/lib/generated/prisma
|
||||||
|
pnpm-lock.yaml
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
//import { error } from "console";
|
import { error } from "console";
|
||||||
import Papa from "papaparse";
|
import Papa from "papaparse";
|
||||||
import { createSong } from "@/lib/db/song";
|
|
||||||
//import { createSongBook } from "@/lib/db/songbook.ts";
|
|
||||||
import { addSongToBook } from "@/lib/db/songbooksongs.ts";
|
|
||||||
|
|
||||||
|
|
||||||
interface CSVRow {
|
interface CSVRow {
|
||||||
nummer: string;
|
nummer: string;
|
||||||
@@ -34,8 +30,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.number}, Titel: ${row.titel}`);
|
console.log(`Nummer: ${row.nummer}, 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.`};
|
||||||
|
|||||||
+73
-55
@@ -1,39 +1,46 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { uploadCSVAction } from "./actions";
|
import { uploadCSVAction } from "./actions";
|
||||||
import { useEffect, useState } from "react";
|
import { JSXElementConstructor, Key, ReactElement, ReactNode, ReactPortal, useEffect, useState } from "react";
|
||||||
|
|
||||||
import Card from "@/components/Card"
|
import Card from "@/components/Card"
|
||||||
import { Input } from "@/components/FormElements";
|
import { Input } from "@/components/FormElements";
|
||||||
import { Screens } from "@/components/AllSongsTable";
|
import { Screens } from "@/components/DatabaseOverview";
|
||||||
|
|
||||||
import { Song, SongBook, SongDetailed } from "@/lib/db/response";
|
interface Songbook {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Song {
|
||||||
|
song_id: number;
|
||||||
|
songbook_id: number;
|
||||||
|
song_number: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SongInfo {
|
||||||
|
songbook_id: number;
|
||||||
|
songbook_title: string;
|
||||||
|
song_number: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function AdminPage() {
|
export default function AdminPage() {
|
||||||
// New Songbook
|
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
||||||
const [newBookTitle, setNewBookTitle] = useState("");
|
const [selectedSongbookId, setSelectedSongbookId] = useState("");
|
||||||
const [newBookLanguage, setNewBookLanguage] = useState("");
|
|
||||||
|
|
||||||
// New Song
|
|
||||||
const [addSongSelectedSongbookId, addSongSetSelectedSongbookId] = useState("");
|
|
||||||
const [number, setNumber] = useState("");
|
const [number, setNumber] = useState("");
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
|
|
||||||
// Import Songs
|
const [newBookTitle, setNewBookTitle] = useState("");
|
||||||
const [importSelectedSongbookId, importSetSelectedSongbookId] = useState("");
|
const [newBookLanguage, setNewBookLanguage] = useState("");
|
||||||
|
|
||||||
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
const [songbooks, setSongbooks] = useState<SongBook[]>([]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
||||||
const [songInfos, setSongInfos] = useState<SongDetailed[]>([])
|
const [songInfos, setSongInfos] = useState<SongInfo[]>([])
|
||||||
|
|
||||||
async function handleCSVUpload(formData: FormData) {
|
async function handleCSVUpload(formData: FormData) {
|
||||||
setUploadStatus("Verarbeite...");
|
setUploadStatus("Verarbeite...");
|
||||||
@@ -54,7 +61,7 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
async function fetchSongInfos() {
|
async function fetchSongInfos() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/songs/${selectedSong?.id}`);
|
const res = await fetch(`/api/songs/${selectedSong?.song_id}`);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setSongInfos(data);
|
setSongInfos(data);
|
||||||
@@ -83,27 +90,40 @@ export default function AdminPage() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const addSong = async () => {
|
const addSong = async () => {
|
||||||
if (!addSongSelectedSongbookId || !number || !title) {
|
if (!selectedSongbookId || !number || !title) {
|
||||||
alert("Alle Felder ausfüllen!");
|
alert("Alle Felder ausfüllen!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/songs", {
|
// Create song
|
||||||
|
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(addSongSelectedSongbookId),
|
|
||||||
number: number,
|
|
||||||
title: title
|
title: title
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
if (res.ok) {
|
if (res1.ok) {
|
||||||
alert("Lied erfolgreich hinzugefügt!");
|
console.log("Lied erfolgreich erstellt!");
|
||||||
setNumber("");
|
|
||||||
setTitle("");
|
|
||||||
} else {
|
} else {
|
||||||
alert("Fehler beim Senden.");
|
console.log("Lied erstellen fehlgeschlagen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
@@ -111,25 +131,23 @@ export default function AdminPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const attachSong = async () => {
|
const attachSong = async () => {
|
||||||
if (!addSongSelectedSongbookId || !number || !selectedSong) {
|
if (!selectedSongbookId || !number || !selectedSong) {
|
||||||
alert("Alle Felder ausfüllen!");
|
alert("Alle Felder ausfüllen!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/songs/attach", {
|
const res2 = await fetch(`/api/songbooks/${Number(selectedSongbookId)}/songs/${selectedSong.song_id}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
songbookId: addSongSelectedSongbookId,
|
number: number
|
||||||
songId: selectedSong.id,
|
|
||||||
number: number,
|
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
if (res.ok) {
|
if (res2.ok) {
|
||||||
alert("Lied erfolgreich zum Liederbuch hinzugefügt!");
|
console.log("Lied erfolgreich dem Liederbuch zugewiesen!");
|
||||||
} else {
|
} else {
|
||||||
alert("Fehler beim Senden.");
|
console.log("Fehler");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed sending current songID:", error);
|
console.error("Failed sending current songID:", error);
|
||||||
@@ -137,7 +155,7 @@ export default function AdminPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const removeSong = async () => {
|
const removeSong = async () => {
|
||||||
if (!addSongSelectedSongbookId || !selectedSong) {
|
if (!selectedSongbookId || !selectedSong) {
|
||||||
alert("Alle Felder ausfüllen!");
|
alert("Alle Felder ausfüllen!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -147,8 +165,8 @@ export default function AdminPage() {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
songbookId: addSongSelectedSongbookId,
|
songbookId: selectedSongbookId,
|
||||||
songId: selectedSong.id
|
songId: selectedSong.song_id
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -163,7 +181,7 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
const addSongbook = async () => {
|
const addSongbook = async () => {
|
||||||
if (!newBookTitle) {
|
if (!newBookTitle) {
|
||||||
alert("Der Name des Liederbuches darf nicht leer sein!");
|
alert("Der Title des Liederbuches darf nicht leer sein!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +189,7 @@ 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({ name: newBookTitle, language: newBookLanguage })
|
body: JSON.stringify({ title: newBookTitle, language: newBookLanguage })
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -235,8 +253,8 @@ export default function AdminPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Input.Label>Liederbuch wählen</Input.Label>
|
<Input.Label>Liederbuch wählen</Input.Label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={addSongSelectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="">-- Bitte wählen --</option>
|
<option value="">-- Bitte wählen --</option>
|
||||||
{songbooks.map((book) => (
|
{songbooks.map((book) => (
|
||||||
@@ -272,13 +290,13 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
<Card title="CSV-Massenimport">
|
<Card title="CSV-Massenimport">
|
||||||
<form action={handleCSVUpload} className="flex flex-col justify-between">
|
<form action={handleCSVUpload} className="flex flex-col justify-between">
|
||||||
<input type="hidden" name="songbookId" value={addSongSelectedSongbookId} />
|
<input type="hidden" name="songbookId" value={selectedSongbookId} />
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<Input.Label>Ziel-Liederbuch</Input.Label>
|
<Input.Label>Ziel-Liederbuch</Input.Label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={addSongSelectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="">-- Bitte wählen --</option>
|
<option value="">-- Bitte wählen --</option>
|
||||||
{songbooks.map((book) => (
|
{songbooks.map((book) => (
|
||||||
@@ -322,13 +340,13 @@ export default function AdminPage() {
|
|||||||
<Input.Text value={selectedSong ? selectedSong.title : ""} disabled></Input.Text>
|
<Input.Text value={selectedSong ? selectedSong.title : ""} disabled></Input.Text>
|
||||||
<Card title="Informationen" className="mt-4">
|
<Card title="Informationen" className="mt-4">
|
||||||
<div className="text-sm space-y-1">
|
<div className="text-sm space-y-1">
|
||||||
<p><span className="font-semibold">Lied-ID:</span> {selectedSong?.id ?? "-"}</p>
|
<p><span className="font-semibold">Lied-ID:</span> {selectedSong?.song_id ?? "-"}</p>
|
||||||
<p><span className="font-semibold">In Liederbüchern:</span></p>
|
<p><span className="font-semibold">In Liederbüchern:</span></p>
|
||||||
{songInfos.length > 0 ? (
|
{songInfos.length > 0 ? (
|
||||||
<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_name} (Nr. {info.song_number})
|
{info.songbook_title} (Nr. {info.song_number})
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -343,8 +361,8 @@ export default function AdminPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Input.Label>Ziel-Liederbuch</Input.Label>
|
<Input.Label>Ziel-Liederbuch</Input.Label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={addSongSelectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="">-- Bitte wählen --</option>
|
<option value="">-- Bitte wählen --</option>
|
||||||
{songbooks.map((book) => (
|
{songbooks.map((book) => (
|
||||||
@@ -376,14 +394,14 @@ export default function AdminPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Input.Label>Ziel-Liederbuch</Input.Label>
|
<Input.Label>Ziel-Liederbuch</Input.Label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={addSongSelectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="">-- Bitte wählen --</option>
|
<option value="">-- Bitte wählen --</option>
|
||||||
{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_name} (Nr. {info.song_number})
|
{info.songbook_title} (Nr. {info.song_number})
|
||||||
</option>
|
</option>
|
||||||
))
|
))
|
||||||
): ""}
|
): ""}
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
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
|
||||||
@@ -33,12 +28,12 @@ interface RouteParams {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
@@ -86,11 +81,11 @@ export async function GET(_request: Request, { params }: RouteParams) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }: RouteParams) {
|
export async function PATCH(request: Request, { params }) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSongBook(parseInt(songBookId), data);
|
const res = await updateSongBook(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 });
|
||||||
@@ -131,10 +126,10 @@ export async function PATCH(request: Request, { params }: RouteParams) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function DELETE(_request: Request, { params }: RouteParams) {
|
export async function DELETE(request: Request, { params }) {
|
||||||
try {
|
try {
|
||||||
const { songBookId } = await params;
|
const { songBookId } = await params;
|
||||||
const res = await deleteSongBook(parseInt(songBookId));
|
const res = await deleteSongBook(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 });
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
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
|
||||||
@@ -51,13 +45,13 @@ interface RouteParams {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function POST(request: Request, { params }: RouteParams) {
|
export async function POST(request: Request, { params }) {
|
||||||
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(parseInt(songId), parseInt(songBookId), String(data.number));
|
const res = await addSongToBook(songId, songBookId, data.number);
|
||||||
|
|
||||||
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
@@ -120,11 +114,11 @@ export async function POST(request: Request, { params }: RouteParams) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }: RouteParams) {
|
export async function PATCH(request: Request, { params }) {
|
||||||
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(parseInt(songId), parseInt(songBookId), data);
|
const res = await updateSongInBook(songId, 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 });
|
||||||
@@ -171,11 +165,11 @@ export async function PATCH(request: Request, { params }: RouteParams) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function DELETE(_request: Request, { params }: RouteParams) {
|
export async function DELETE(request: Request, { params }) {
|
||||||
try {
|
try {
|
||||||
const { songBookId, songId } = await params;
|
const { songBookId, songId } = await params;
|
||||||
|
|
||||||
const res = await removeSongFromBook(parseInt(songId), parseInt(songBookId));
|
const res = await removeSongFromBook(songId, 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 });
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
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
|
||||||
@@ -31,14 +26,14 @@ interface RouteParams {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
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 { 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(parseInt(songBookId), number);
|
const res = await getSongByNumber(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 });
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
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
|
||||||
@@ -31,10 +27,10 @@ interface RouteParams {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function GET(_request: Request, { params }: RouteParams) {
|
export async function GET(request: Request, { params }) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const res = await getSongById(parseInt(songId));
|
const res = await getSongById(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 });
|
||||||
@@ -81,11 +77,11 @@ export async function GET(_request: Request, { params }: RouteParams) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function PATCH(request: Request, { params }: RouteParams) {
|
export async function PATCH(request: Request, { params }) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const res = await updateSong(parseInt(songId), data);
|
const res = await updateSong(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 });
|
||||||
@@ -126,10 +122,10 @@ export async function PATCH(request: Request, { params }: RouteParams) {
|
|||||||
* 500:
|
* 500:
|
||||||
* description: Serverfehler
|
* description: Serverfehler
|
||||||
*/
|
*/
|
||||||
export async function DELETE(_request: Request, { params }: RouteParams) {
|
export async function DELETE(request: Request, { params }) {
|
||||||
try {
|
try {
|
||||||
const { songId } = await params;
|
const { songId } = await params;
|
||||||
const res = await deleteSong(parseInt(songId));
|
const res = await deleteSong(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 });
|
||||||
|
|||||||
@@ -110,7 +110,10 @@ 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 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// @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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
// @wikiCategory: Stream
|
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
|
||||||
|
|
||||||
|
|
||||||
let currentSong = {
|
|
||||||
number: "",
|
|
||||||
song: "",
|
|
||||||
songbook: "",
|
|
||||||
};
|
|
||||||
const clients = new Set<ReadableStreamDefaultController>();
|
|
||||||
|
|
||||||
|
|
||||||
// @wikiDescription: Akutell gestreamtes Lied abrufen
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// @wikiDescription: Lied zum Streamen festlegen
|
|
||||||
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 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-3
@@ -26,11 +26,10 @@ export default function RootLayout({
|
|||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<body className="min-h-screen min-w-80 flex flex-col">
|
<body className="min-h-screen flex flex-col">
|
||||||
|
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
<main className="mt-28 sm:mt-20 mx-auto w-full max-w-6xl px-4 sm:px-6 lg:px-8">{children}</main>
|
<main className="mt-20 mx-auto min-w-200 max-w-full">{children}</main>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+77
-7
@@ -1,27 +1,97 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Screens } from "@/components/AllSongsTable";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
|
import { Input } from "@/components/FormElements";
|
||||||
|
import { Screens } from "@/components/DatabaseOverview";
|
||||||
|
|
||||||
|
interface Songbook {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Song {
|
||||||
|
song_id: number;
|
||||||
|
songbook_id: number;
|
||||||
|
song_number: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function SenderPage() {
|
export default function SenderPage() {
|
||||||
const sendSong = async (title: string, bookTitle: string, number: string) => {
|
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
||||||
|
const [song_search_name, setSongSearchName] = useState("");
|
||||||
|
const [allSongs, setAllSongs] = useState<Song[]>([]);
|
||||||
|
const [searchResults, setSearchResults] = useState<Song[]>([]);
|
||||||
|
|
||||||
|
const getSongslist = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/stream", {
|
const res = await fetch("/api/songs");
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setAllSongs(data);
|
||||||
|
setSearchResults(data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setAllSongs([]);
|
||||||
|
console.error("Failed fetching songslist!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function loadSongbooks() {
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/songbooks");
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setSongbooks(data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Loading songbooks failed: ", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadSongbooks();
|
||||||
|
getSongslist();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const sendID = async (sID: string, sbID: string) => {
|
||||||
|
if (!sID || !sbID) {
|
||||||
|
alert("Bitte Liederbuch UND SongID auswählen/eingeben!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/stream/currentID", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ song: title, songBook: bookTitle, number }),
|
body: JSON.stringify({ songbookID: sbID, songID: sID }),
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
alert("Fehler beim Senden.");
|
alert("Fehler beim Senden.");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed sending current song:", error);
|
console.error("Failed sending current songID:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const search = (query: string) => {
|
||||||
|
setSongSearchName(query);
|
||||||
|
if (query.trim() !== "") {
|
||||||
|
setSearchResults(
|
||||||
|
allSongs.filter((song) =>
|
||||||
|
song.title.toLowerCase().includes(query.toLowerCase()) ||
|
||||||
|
song.song_number.includes(query)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setSearchResults(allSongs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screens.Songs
|
<Screens.Songs
|
||||||
actionName="Anzeigen"
|
actionName="Anzeigen"
|
||||||
onSelectSong={(song, book, number) => sendSong(song.title, book.title, number)}
|
onSelectSong={(song) => sendID(String(song.song_id), String(song.songbook_id))}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
import { useState, useEffect, useMemo, ComponentPropsWithoutRef } from "react";
|
|
||||||
|
|
||||||
import Card from "./Card"
|
|
||||||
import { Input } from "./FormElements"
|
|
||||||
import { Song, SongBookDetailed } from "@/lib/db/response";
|
|
||||||
|
|
||||||
interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title" | "children"> {
|
|
||||||
onSelectSong?: (song: Song, book: { id: number; title: string }, songNumber: string) => void;
|
|
||||||
actionName?: string;
|
|
||||||
songBooks?: SongBookDetailed[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function Songs({ actionName, onSelectSong, songBooks, className = "", ...props }: SongsProps) {
|
|
||||||
const [query, setQuery] = useState("");
|
|
||||||
const [fetchedBooks, setFetchedBooks] = useState<SongBookDetailed[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (songBooks) return;
|
|
||||||
async function load() {
|
|
||||||
try {
|
|
||||||
const res = await fetch("/api/songbooks");
|
|
||||||
if (!res.ok) return;
|
|
||||||
const list: { id: number }[] = await res.json();
|
|
||||||
|
|
||||||
const details = await Promise.all(
|
|
||||||
list.map(async (b) => {
|
|
||||||
const r = await fetch(`/api/songbooks/${b.id}`);
|
|
||||||
return r.ok ? await r.json() : null;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
setFetchedBooks(details.filter(Boolean));
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Loading songbooks failed: ", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
load();
|
|
||||||
}, [songBooks]);
|
|
||||||
|
|
||||||
const books = songBooks ?? fetchedBooks;
|
|
||||||
|
|
||||||
// Pro Buch filtern; Bücher ohne Treffer werden ausgeblendet
|
|
||||||
const groups = useMemo(() => {
|
|
||||||
const q = query.trim().toLowerCase();
|
|
||||||
return books
|
|
||||||
.map((book) => {
|
|
||||||
const bookMatches = q !== "" && book.title.toLowerCase().includes(q);
|
|
||||||
const songs = (book.songs ?? []).filter(
|
|
||||||
(e) =>
|
|
||||||
!q ||
|
|
||||||
bookMatches ||
|
|
||||||
e.song.title.toLowerCase().includes(q) ||
|
|
||||||
String(e.songNumber).toLowerCase().includes(q)
|
|
||||||
);
|
|
||||||
return { book, songs };
|
|
||||||
})
|
|
||||||
.filter((g) => g.songs.length > 0);
|
|
||||||
}, [books, query]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card {...props} title="Alle Lieder" className={className}>
|
|
||||||
<div className="mb-3">
|
|
||||||
<Input.Text
|
|
||||||
type="text"
|
|
||||||
placeholder="Titel, Nummer oder Liederbuch suchen..."
|
|
||||||
value={query}
|
|
||||||
onChange={(e) => setQuery(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="max-h-[65vh] overflow-y-auto border border-neutral-200 dark:border-neutral-800 rounded-lg bg-white dark:bg-black">
|
|
||||||
{groups.length === 0 ? (
|
|
||||||
<p className="p-8 text-center text-neutral-400 dark:text-neutral-500">
|
|
||||||
Keine Lieder gefunden
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
groups.map(({ book, songs }) => (
|
|
||||||
<section key={book.id}>
|
|
||||||
<h3 className="sticky top-0 z-10 px-3 py-2 text-sm font-bold bg-neutral-100 dark:bg-neutral-900 text-neutral-900 dark:text-white border-y border-neutral-200 dark:border-neutral-800">
|
|
||||||
{book.title}
|
|
||||||
{book.language && (
|
|
||||||
<span className="ml-2 text-xs font-normal text-neutral-500">
|
|
||||||
({book.language})
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</h3>
|
|
||||||
<ul className="divide-y divide-neutral-200 dark:divide-neutral-800">
|
|
||||||
{songs.map((entry) => (
|
|
||||||
<li
|
|
||||||
key={`${book.id}-${entry.song.id}`}
|
|
||||||
className="flex flex-wrap items-center gap-x-3 gap-y-2 px-3 py-2.5"
|
|
||||||
>
|
|
||||||
<span className="w-12 shrink-0 text-center font-mono font-bold text-blue-600 dark:text-blue-400">
|
|
||||||
{entry.songNumber}
|
|
||||||
</span>
|
|
||||||
<span className="flex-1 min-w-40 break-words font-medium text-neutral-900 dark:text-white">
|
|
||||||
{entry.song.title}
|
|
||||||
</span>
|
|
||||||
<Input.Button
|
|
||||||
onClick={() => onSelectSong?.(entry.song, { id: book.id, title: book.title }, String(entry.songNumber))}
|
|
||||||
className="shrink-0 w-auto px-3 py-2 text-xs"
|
|
||||||
>
|
|
||||||
{actionName}
|
|
||||||
</Input.Button>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Screens = {
|
|
||||||
Songs: Songs,
|
|
||||||
}
|
|
||||||
+1
-1
@@ -17,7 +17,7 @@ export default function Card({ title, hasLeftBorder = false, children, className
|
|||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
{/* border-l-2 fügt den Strich links ein, pl-4 macht Platz zum Inhalt */}
|
{/* border-l-2 fügt den Strich links ein, pl-4 macht Platz zum Inhalt */}
|
||||||
<div className={`flex-1 min-h-0 flex flex-col border-neutral-200 dark:border-neutral-800 ${hasLeftBorder ? "border-l-2 pl-4" : ""}`}>
|
<div className={`flex-1 min-h-0 flex flex-col border-neutral-200 dark:border-neutral-800 ${hasLeftBorder ? "border-l-2 pl-4}" : ""}`}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
import { useState, useEffect, ComponentPropsWithoutRef } from "react";
|
||||||
|
|
||||||
|
import Card from "./Card";
|
||||||
|
import { Input } from "./FormElements";
|
||||||
|
|
||||||
|
interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title" | "children"> {
|
||||||
|
onSelectSong?: (song: Song) => void;
|
||||||
|
actionName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Song {
|
||||||
|
id: number;
|
||||||
|
songbook_id: number;
|
||||||
|
song_number: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Songbook {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Songs({ actionName = "Auswählen", onSelectSong, className = "", ...props }: SongsProps) {
|
||||||
|
const [song_search_name, setSongSearchName] = useState("");
|
||||||
|
const [searchResults, setSearchResults] = useState<Song[]>([]);
|
||||||
|
const [allSongs, setAllSongs] = useState<Song[]>([]);
|
||||||
|
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
||||||
|
|
||||||
|
const search = (query: string) => {
|
||||||
|
setSongSearchName(query);
|
||||||
|
if (query.trim() !== "") {
|
||||||
|
setSearchResults(
|
||||||
|
allSongs.filter((song) =>
|
||||||
|
song.title.toLowerCase().includes(query.toLowerCase()) ||
|
||||||
|
song.song_number.includes(query)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setSearchResults(allSongs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getSongslist = async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/songs");
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setAllSongs(data);
|
||||||
|
setSearchResults(data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setAllSongs([]);
|
||||||
|
console.error("Failed fetching songslist!", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function loadSongbooks() {
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/songbooks");
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setSongbooks(data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Loading songbooks failed: ", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadSongbooks();
|
||||||
|
getSongslist();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
{...props}
|
||||||
|
title="Alle Lieder"
|
||||||
|
className={`h-[500px] ${className}`}
|
||||||
|
>
|
||||||
|
<div className="mb-4">
|
||||||
|
<Input.Text
|
||||||
|
type="text"
|
||||||
|
placeholder="Nach Songtitel oder Nummer suchen..."
|
||||||
|
value={song_search_name}
|
||||||
|
onChange={(e) => search(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 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">
|
||||||
|
<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">
|
||||||
|
<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">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-right">Aktion</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-neutral-200 dark:divide-neutral-800">
|
||||||
|
{searchResults.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={4} className="p-8 text-center text-neutral-400 dark:text-neutral-500">Keine Lieder gefunden</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
searchResults.map((song) => {
|
||||||
|
const songBook = songbooks.find((book) => book.id === song.songbook_id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<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">
|
||||||
|
{song.title}
|
||||||
|
<span className="block text-xs text-neutral-500 dark:text-neutral-400 sm:hidden mt-0.5">
|
||||||
|
{songBook ? songBook.title : "Unbekannt"}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td className="p-3 text-neutral-700 dark:text-neutral-300 hidden sm:table-cell">
|
||||||
|
{songBook ? songBook.title : "Unbekannt"}
|
||||||
|
</td>
|
||||||
|
<td className="p-3 text-center font-mono text-blue-600 dark:text-blue-400 font-bold">
|
||||||
|
{song.song_number}
|
||||||
|
</td>
|
||||||
|
<td className="p-3 text-right">
|
||||||
|
<Input.Button
|
||||||
|
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"
|
||||||
|
>
|
||||||
|
{actionName}
|
||||||
|
</Input.Button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Screens = {
|
||||||
|
Songs: Songs,
|
||||||
|
};
|
||||||
@@ -36,13 +36,13 @@ function File({ ...props }: ComponentPropsWithoutRef<"input">) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Button({ children, className = "", ...props }: ComponentPropsWithoutRef<"button">) {
|
function Button({ children, ...props }: ComponentPropsWithoutRef<"button">) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
className={`bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm ${className || "w-full"}`}
|
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm"
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import NavItem from "./NavItem";
|
|||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
return (
|
return (
|
||||||
<header className="fixed top-0 left-0 w-full min-w-80 z-50 p-3 sm:p-4 flex flex-wrap gap-2 justify-between items-center backdrop-blur-md border-b-2 border-slate-500">
|
<header className="fixed top-0 left-0 w-full z-50 p-4 flex justify-between items-center backdrop-blur-md border-b-2 border-slate-500">
|
||||||
<div className="font-bold text-xl">PsalmTafel</div>
|
<div className="font-bold text-xl">PsalmTafel</div>
|
||||||
<nav className="flex flex-wrap gap-1 sm:gap-4 border-2 rounded-full text-sm">
|
<nav className="flex gap-4 border-2 rounded-full">
|
||||||
<NavItem path="/dashboard">Dashboard</NavItem>
|
<NavItem path="/dashboard">Dashboard</NavItem>
|
||||||
<NavItem path="/sender">Sender</NavItem>
|
<NavItem path="/sender">Sender</NavItem>
|
||||||
<NavItem path="/receiver">Empfänger</NavItem>
|
<NavItem path="/receiver">Empfänger</NavItem>
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
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 interface SongBookDetailed {
|
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
language: string;
|
|
||||||
songs?: {
|
|
||||||
songNumber: string;
|
|
||||||
song: Song;
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
|
|
||||||
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>;
|
|
||||||
+8
-15
@@ -1,14 +1,7 @@
|
|||||||
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
|
||||||
@@ -16,7 +9,7 @@ interface Response {
|
|||||||
*
|
*
|
||||||
* @returns {"success": boolean, "status": number, "songs": [{"id":number, "title": string},...]}
|
* @returns {"success": boolean, "status": number, "songs": [{"id":number, "title": string},...]}
|
||||||
*/
|
*/
|
||||||
export async function getSongs(): Promise<API.GetSongsResponse> {
|
export async function getSongs() {
|
||||||
try{
|
try{
|
||||||
const songs = await prisma.song.findMany({
|
const songs = await prisma.song.findMany({
|
||||||
select: {
|
select: {
|
||||||
@@ -42,7 +35,7 @@ export async function getSongs(): Promise<API.GetSongsResponse> {
|
|||||||
* @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): Promise<API.GetSongDetailedResponse> {
|
export async function getSongById(rawId: number) {
|
||||||
try{
|
try{
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -85,13 +78,13 @@ export async function getSongById(rawId: number): Promise<API.GetSongDetailedRes
|
|||||||
*
|
*
|
||||||
* @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 {"success": boolean, "status": number, "song": {"id":number, "title": string, "songBooks": [{"songNumber": number, "book": {"title": string, "language": string}},...]}}
|
* @returns @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): Promise<API.GetSongsDelailedResponse> {
|
export async function searchSongsByTitle(query: string, limit: number = 20) {
|
||||||
try {
|
try {
|
||||||
const cleanQuery = query.trim();
|
const cleanQuery = query.trim();
|
||||||
if (!cleanQuery) {
|
if (!cleanQuery) {
|
||||||
return { success: true, status: 200, songs: [] };
|
return { success: true, songBooks: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const songs = await prisma.song.findMany({
|
const songs = await prisma.song.findMany({
|
||||||
@@ -131,7 +124,7 @@ export async function searchSongsByTitle(query: string, limit: number = 20): Pro
|
|||||||
* @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 }): Promise<API.CreateSongsResponse> {
|
export async function createSong(data: { title: string }) {
|
||||||
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" };
|
||||||
@@ -171,7 +164,7 @@ export async function createSong(data: { title: string }): Promise<API.CreateSon
|
|||||||
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) {
|
||||||
@@ -220,7 +213,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): Promise<API.CreateSongsResponse> {
|
export async function deleteSong(rawId: number) {
|
||||||
try {
|
try {
|
||||||
const id = parseInt(rawId);
|
const id = parseInt(rawId);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
export function parseInt(rawInteger: number){
|
export function parseInt(rawInteger){
|
||||||
const integer = Number.parseInt(rawInteger);
|
const integer = Number.parseInt(rawInteger);
|
||||||
|
|
||||||
if (Number.isNaN(integer) || !Number.isInteger(integer)) {
|
if (Number.isNaN(integer) || !Number.isInteger(integer)) {
|
||||||
|
|||||||
+5
-1
@@ -6,7 +6,11 @@
|
|||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "eslint"
|
"lint": "eslint",
|
||||||
|
"postinstall": "prisma generate",
|
||||||
|
"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",
|
||||||
|
|||||||
Reference in new issue
Block a user