Feat/admin options #14
No files matched your search
+24
-2
@@ -118,7 +118,29 @@ export default function AdminPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const attachSong = async () => {
|
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 () => {
|
const addSongbook = async () => {
|
||||||
@@ -319,8 +341,8 @@ export default function AdminPage() {
|
|||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="12a"
|
placeholder="12a"
|
||||||
value={title}
|
value={number}
|
||||||
onChange={(e) => setTitle(e.target.value)}
|
onChange={(e) => setNumber(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Input.Button
|
<Input.Button
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ export async function POST(request: Request) {
|
|||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { songId, songbookId, number } = body;
|
const { songId, songbookId, number } = body;
|
||||||
|
|
||||||
if (!songId || !songbookId || !number) {
|
if (isNaN(songId) || isNaN(songbookId) || !number) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "songId, songbookId und number sind erforderlich." },
|
{ error: "Ungültige IDs oder fehlende Nummer." },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-5
@@ -122,16 +122,26 @@ export async function addSongToSongbook(title:string, songbookId:number, number:
|
|||||||
|
|
||||||
export async function attachSongToSongbook(songId: number, songbookId: number, number: string) {
|
export async function attachSongToSongbook(songId: number, songbookId: number, number: string) {
|
||||||
try {
|
try {
|
||||||
const runTransaction = db.transaction(() => {
|
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(`
|
db.prepare(`
|
||||||
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
|
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
`).run(songbookId, songId, number);
|
`).run(songbookId, songId, number);
|
||||||
})
|
|
||||||
runTransaction();
|
return { success: true };
|
||||||
return { success: true }
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in addSongToSongbook:", error);
|
console.error("Error in attachSongToSongbook:", error);
|
||||||
return { success: false };
|
return { success: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user