From 8910a1ff0565dc4a13bf3a0c04f125db55c56768 Mon Sep 17 00:00:00 2001 From: Robin Schanbacher Date: Tue, 28 Jul 2026 15:32:48 +0200 Subject: [PATCH] feat: add attachSongToSongbook to db managing.ts --- app/admin/page.tsx | 46 +++++++++++++++++++++++++++++++++++----------- lib/db/managing.ts | 20 ++++++++++++++++++-- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/app/admin/page.tsx b/app/admin/page.tsx index 6270d9a..99b4f3e 100644 --- a/app/admin/page.tsx +++ b/app/admin/page.tsx @@ -117,6 +117,10 @@ export default function AdminPage() { } }; + const attachSong = async () => { + + } + const addSongbook = async () => { if (!newBookName) { alert("Der Name des Liederbuches darf nicht leer sein!"); @@ -295,17 +299,37 @@ export default function AdminPage() { - setSelectedSongbookId(e.target.value)} - > - - {songbooks.map((book) => ( - - ))} - +
+
+ Ziel-Liederbuch + setSelectedSongbookId(e.target.value)} + > + + {songbooks.map((book) => ( + + ))} + +
+
+ Nummer + setTitle(e.target.value)} + /> +
+ + Lied hinzufügen + +
diff --git a/lib/db/managing.ts b/lib/db/managing.ts index f36e703..05b4399 100644 --- a/lib/db/managing.ts +++ b/lib/db/managing.ts @@ -86,7 +86,7 @@ export async function getSongInfos(songId: string) { song_number: string; title: string; }[] | undefined - + return songRecords || null; } catch (error) { console.error("Fehler in getSong:", error); @@ -120,6 +120,22 @@ 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 } + } catch (error) { + console.error("Error in addSongToSongbook:", error); + return { success: false }; + } +} + export async function getSongbooks() { try { const songbooks = db.prepare('SELECT id, name, language FROM songbooks ORDER BY name ASC').all(); @@ -129,7 +145,7 @@ export async function getSongbooks() { } } -export async function addSongbook(name:String, language:String) { +export async function addSongbook(name: string, language: string) { try { const info = db.prepare(` INSERT INTO songbooks (name, language)