Feat/admin options #14

Merged
robin merged 20 commits from feat/admin-options into main 2026-07-28 15:05:03 +00:00
3 changed files with 45 additions and 13 deletions
Showing only changes of commit e3115df0bd - Show all commits

No files matched your search

+24 -2
View File
@@ -118,7 +118,29 @@ export default function AdminPage() {
};
const attachSong = async () => {
if (!selectedSongbookId || !number || !selectedSong) {
alert("Alle Felder ausfüllen!");
return;
}
try {
const res = await fetch("/api/songs/attach", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
songbookId: selectedSongbookId,
songId: selectedSong.song_id,
number: number,
})
});
if (res.ok) {
alert("Loed erfolgreich zum Liederbuch hinzugefügt!");
} else {
alert("Fehler beim Senden.");
}
} catch (error) {
console.error("Failed sending current songID:", error);
}
}
const addSongbook = async () => {
@@ -319,8 +341,8 @@ export default function AdminPage() {
<Input.Text
type="text"
placeholder="12a"
value={title}
onChange={(e) => setTitle(e.target.value)}
value={number}
onChange={(e) => setNumber(e.target.value)}
/>
</div>
<Input.Button
+2 -2
View File
@@ -6,9 +6,9 @@ export async function POST(request: Request) {
const body = await request.json();
const { songId, songbookId, number } = body;
if (!songId || !songbookId || !number) {
if (isNaN(songId) || isNaN(songbookId) || !number) {
return NextResponse.json(
{ error: "songId, songbookId und number sind erforderlich." },
{ error: "Ungültige IDs oder fehlende Nummer." },
{ status: 400 }
);
}
+19 -9
View File
@@ -122,16 +122,26 @@ export async function addSongToSongbook(title:string, songbookId:number, number:
export async function attachSongToSongbook(songId: number, songbookId: number, number: string) {
try {
const runTransaction = db.transaction(() => {
db.prepare(`
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
VALUES (?, ?, ?)
`).run(songbookId, songId, number);
})
runTransaction();
return { success: true }
const songExists = db.prepare("SELECT id FROM songs WHERE id = ?").get(songId);
if (!songExists) {
console.error(`Song mit ID ${songId} existiert nicht in DB.`);
return { success: false, error: "Song nicht gefunden." };
}
const bookExists = db.prepare("SELECT id FROM songbooks WHERE id = ?").get(songbookId);
if (!bookExists) {
console.error(`Songbook mit ID ${songbookId} existiert nicht in DB.`);
return { success: false, error: "Liederbuch nicht gefunden." };
}
db.prepare(`
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
VALUES (?, ?, ?)
`).run(songbookId, songId, number);
return { success: true };
} catch (error) {
console.error("Error in addSongToSongbook:", error);
console.error("Error in attachSongToSongbook:", error);
return { success: false };
}
}