feat: add attachSongToSongbook to db managing.ts
This commit is contained in:
1 parent
d871bddc99
commit
8910a1ff05
2 files changed
+53
-13
No files matched your search
+35
-11
@@ -117,6 +117,10 @@ export default function AdminPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const attachSong = async () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const addSongbook = async () => {
|
const addSongbook = async () => {
|
||||||
if (!newBookName) {
|
if (!newBookName) {
|
||||||
alert("Der Name des Liederbuches darf nicht leer sein!");
|
alert("Der Name des Liederbuches darf nicht leer sein!");
|
||||||
@@ -295,17 +299,37 @@ export default function AdminPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
<Card title="Aktionen">
|
<Card title="Aktionen">
|
||||||
<Card title="Zu Liederbuch hinzufügen">
|
<Card title="Zu Liederbuch hinzufügen">
|
||||||
<Input.Select
|
<div className="space-y-4">
|
||||||
value={selectedSongbookId}
|
<div>
|
||||||
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
<Input.Label>Ziel-Liederbuch</Input.Label>
|
||||||
>
|
<Input.Select
|
||||||
<option value="">-- Bitte wählen --</option>
|
value={selectedSongbookId}
|
||||||
{songbooks.map((book) => (
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
<option key={book.id} value={String(book.id)}>
|
>
|
||||||
{book.name}{book.language ? ` (${book.language})` : ""}
|
<option value="">-- Bitte wählen --</option>
|
||||||
</option>
|
{songbooks.map((book) => (
|
||||||
))}
|
<option key={book.id} value={String(book.id)}>
|
||||||
</Input.Select>
|
{book.name}{book.language ? ` (${book.language})` : ""}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Input.Select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Input.Label>Nummer</Input.Label>
|
||||||
|
<Input.Text
|
||||||
|
type="text"
|
||||||
|
placeholder="12a"
|
||||||
|
value={title}
|
||||||
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Input.Button
|
||||||
|
onClick={attachSong}
|
||||||
|
className="w-full mt-6 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm"
|
||||||
|
>
|
||||||
|
Lied hinzufügen
|
||||||
|
</Input.Button>
|
||||||
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Card>
|
</Card>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
+18
-2
@@ -86,7 +86,7 @@ export async function getSongInfos(songId: string) {
|
|||||||
song_number: string;
|
song_number: string;
|
||||||
title: string;
|
title: string;
|
||||||
}[] | undefined
|
}[] | undefined
|
||||||
|
|
||||||
return songRecords || null;
|
return songRecords || null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Fehler in getSong:", 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() {
|
export async function getSongbooks() {
|
||||||
try {
|
try {
|
||||||
const songbooks = db.prepare('SELECT id, name, language FROM songbooks ORDER BY name ASC').all();
|
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 {
|
try {
|
||||||
const info = db.prepare(`
|
const info = db.prepare(`
|
||||||
INSERT INTO songbooks (name, language)
|
INSERT INTO songbooks (name, language)
|
||||||
|
|||||||
Reference in new issue
Block a user