Main #21
No files matched your search
+25
-3
@@ -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
|
||||
|
||||
@@ -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
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user