Compare commits

...
Author SHA1 Message Date
robin edd33ab712 chore: auto init of database 2026-10-12 16:29:11 +02:00
robin fde1f27745 fix: create song 2026-08-27 17:29:03 +02:00
robin 583ef90a7b fix: POST currentID 2026-08-27 16:26:45 +02:00
robin 2fb484ad26 chore: update .gitignore 2026-08-27 16:16:41 +02:00
7 changed files with 157 additions and 112 deletions

No files matched your search

+1
View File
@@ -46,3 +46,4 @@ songs.sqlite
.gitignore
/lib/generated/prisma
pnpm-lock.yaml
+2 -3
View File
@@ -2,7 +2,6 @@
import { error } from "console";
import Papa from "papaparse";
import { addSongToSongbook } from "@/lib/db/managing";
interface CSVRow {
nummer: string;
@@ -31,8 +30,8 @@ export async function uploadCSVAction(formData:FormData) {
console.log("Data:", rows);
rows.forEach(row => {
//console.log(`Nummer: ${row.number}, Titel: ${row.titel}`);
addSongToSongbook(String(row.titel), Number(songbookId), String(row.nummer))
console.log(`Nummer: ${row.nummer}, Titel: ${row.titel}`);
//addSongToSongbook(String(row.titel), Number(songbookId), String(row.nummer))
});
return { success: true, message: `${rows.length} Zeilen erfolgreich importiert.`};
+42 -31
View File
@@ -9,7 +9,7 @@ import { Screens } from "@/components/DatabaseOverview";
interface Songbook {
id: number;
name: string;
title: string;
language: string;
}
@@ -22,7 +22,7 @@ interface Song {
interface SongInfo {
songbook_id: number;
songbook_name: string;
songbook_title: string;
song_number: string;
title: string;
}
@@ -34,7 +34,7 @@ export default function AdminPage() {
const [number, setNumber] = useState("");
const [title, setTitle] = useState("");
const [newBookName, setNewBookName] = useState("");
const [newBookTitle, setNewBookTitle] = useState("");
const [newBookLanguage, setNewBookLanguage] = useState("");
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
@@ -96,21 +96,34 @@ export default function AdminPage() {
}
try {
const res = await fetch("/api/songs", {
// Create song
const res1 = await fetch("/api/songs", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
songbookId: Number(selectedSongbookId),
number: number,
title: title
})
});
if (res.ok) {
alert("Lied erfolgreich hinzugefügt!");
setNumber("");
setTitle("");
})
if (res1.ok) {
console.log("Lied erfolgreich erstellt!");
} 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) {
console.error("Failed sending current songID:", error);
@@ -124,19 +137,17 @@ export default function AdminPage() {
}
try {
const res = await fetch("/api/songs/attach", {
const res2 = await fetch(`/api/songbooks/${Number(selectedSongbookId)}/songs/${selectedSong.song_id}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
songbookId: selectedSongbookId,
songId: selectedSong.song_id,
number: number,
number: number
})
});
if (res.ok) {
alert("Lied erfolgreich zum Liederbuch hinzugefügt!");
})
if (res2.ok) {
console.log("Lied erfolgreich dem Liederbuch zugewiesen!");
} else {
alert("Fehler beim Senden.");
console.log("Fehler");
}
} catch (error) {
console.error("Failed sending current songID:", error);
@@ -169,8 +180,8 @@ export default function AdminPage() {
}
const addSongbook = async () => {
if (!newBookName) {
alert("Der Name des Liederbuches darf nicht leer sein!");
if (!newBookTitle) {
alert("Der Title des Liederbuches darf nicht leer sein!");
return;
}
@@ -178,14 +189,14 @@ export default function AdminPage() {
const res = await fetch("/api/songbooks", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: newBookName, language: newBookLanguage })
body: JSON.stringify({ title: newBookTitle, language: newBookLanguage })
});
if (res.ok) {
const createdBook = await res.json();
setSongbooks([...songbooks, createdBook]);
alert("Liederbuch erfolgreich erstellt!");
setNewBookName("");
setNewBookTitle("");
setNewBookLanguage("");
} else {
alert("Failed adding songbook!");
@@ -215,8 +226,8 @@ export default function AdminPage() {
<Input.Text
type="text"
placeholder="z.B. Gesangbuch"
value={newBookName}
onChange={(e) => setNewBookName(e.target.value)}
value={newBookTitle}
onChange={(e) => setNewBookTitle(e.target.value)}
/>
</div>
<div>
@@ -248,7 +259,7 @@ export default function AdminPage() {
<option value="">-- Bitte wählen --</option>
{songbooks.map((book) => (
<option key={book.id} value={String(book.id)}>
{book.name}{book.language ? ` (${book.language})` : ""}
{book.title}{book.language ? ` (${book.language})` : ""}
</option>
))}
</Input.Select>
@@ -290,7 +301,7 @@ export default function AdminPage() {
<option value="">-- Bitte wählen --</option>
{songbooks.map((book) => (
<option key={book.id} value={String(book.id)}>
{book.name}{book.language ? ` (${book.language})` : ""}
{book.title}{book.language ? ` (${book.language})` : ""}
</option>
))}
</Input.Select>
@@ -335,7 +346,7 @@ export default function AdminPage() {
<ul className="list-disc list-inside pl-2 text-xs text-neutral-400">
{songInfos.map((info) => (
<li key={info.songbook_id}>
{info.songbook_name} (Nr. {info.song_number})
{info.songbook_title} (Nr. {info.song_number})
</li>
))}
</ul>
@@ -356,7 +367,7 @@ export default function AdminPage() {
<option value="">-- Bitte wählen --</option>
{songbooks.map((book) => (
<option key={book.id} value={String(book.id)}>
{book.name}{book.language ? ` (${book.language})` : ""}
{book.title}{book.language ? ` (${book.language})` : ""}
</option>
))}
</Input.Select>
@@ -390,7 +401,7 @@ export default function AdminPage() {
{songInfos.length > 0 ? (
songInfos.map((info) => (
<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>
))
): ""}
+4 -1
View File
@@ -110,7 +110,10 @@ export async function POST(request: Request) {
if (!res.success) {
return NextResponse.json(
{ message: res.error },
{
message: res.error,
song: res.song
},
{ status: res.status }
);
}
+40 -15
View File
@@ -1,7 +1,7 @@
// @wikiCategory: Stream
import { NextResponse } from "next/server";
import { getSong } from "@/lib/db/managing";
import { getSongById } from "@/lib/db/song";
let currentSong = {
songID: "",
@@ -19,23 +19,43 @@ export async function GET() {
export async function POST(request: Request) {
try {
const data = await request.json();
const songID = data.songID;
const songbookID = data.songbookID;
const { songID, songbookID } = data;
if (!songID || !songbookID) {
return NextResponse.json({ success: false, error: "Fields incomplete!" }, { status: 400 });
return NextResponse.json(
{ success: false, error: "Fields incomplete!" },
{ status: 400 }
);
}
const song = await getSong(Number(songbookID), String(songID));
const result = await getSongById(songID);
if (song) {
currentSong = {
songID: String(songID),
songbook: song.songbook_name,
number: song.number,
title: song.song_title,
};
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: "",
@@ -43,10 +63,15 @@ export async function POST(request: Request) {
title: "",
};
}
console.log(currentSong);
return NextResponse.json({ success: true });
console.log("Aktualisierter currentSong:", currentSong);
return NextResponse.json({ success: true, currentSong });
} catch (error) {
return NextResponse.json({ success: false, error: "Server-Fehler" }, { status: 500 });
console.error("API POST Error:", error);
return NextResponse.json(
{ success: false, error: "Server-Fehler" },
{ status: 500 }
);
}
}
+63 -61
View File
@@ -1,7 +1,7 @@
import { useState, useEffect, ComponentPropsWithoutRef } from "react";
import Card from "./Card"
import { Input } from "./FormElements"
import Card from "./Card";
import { Input } from "./FormElements";
interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title" | "children"> {
onSelectSong?: (song: Song) => void;
@@ -9,7 +9,7 @@ interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title"
}
interface Song {
song_id: number;
id: number;
songbook_id: number;
song_number: string;
title: string;
@@ -17,43 +17,42 @@ interface Song {
interface Songbook {
id: number;
name: string;
title: string;
language: string;
}
function Songs({ actionName, onSelectSong, className = "", ...props }: SongsProps) {
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)
)
);
setSearchResults(
allSongs.filter((song) =>
song.title.toLowerCase().includes(query.toLowerCase()) ||
song.song_number.includes(query)
)
);
} else {
setSearchResults(allSongs);
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);
}
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!");
setAllSongs([]);
console.error("Failed fetching songslist!", error);
}
};
@@ -61,13 +60,14 @@ function Songs({ actionName, onSelectSong, className = "", ...props }: SongsProp
try {
const res = await fetch("/api/songbooks");
if (res.ok) {
const data = await res.json();
setSongbooks(data);
const data = await res.json();
setSongbooks(data);
}
} catch (error) {
console.error("Loading songbooks failed: ", error);
}
}
loadSongbooks();
getSongslist();
}, []);
@@ -80,64 +80,66 @@ function Songs({ actionName, onSelectSong, className = "", ...props }: SongsProp
>
<div className="mb-4">
<Input.Text
type="text"
placeholder="Nach Songtitel oder Nummer suchen..."
value={song_search_name}
onChange={(e) => search(e.target.value)}
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>
<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>
<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.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.name : "Unbekannt"}
</span>
</td>
<td className="p-3 text-neutral-700 dark:text-neutral-300 hidden sm:table-cell">
{songBook ? songBook.name : "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>
);
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,
}
};
+5 -1
View File
@@ -6,7 +6,11 @@
"dev": "next dev",
"build": "next build",
"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": {
"@prisma/adapter-better-sqlite3": "^7.9.1",