feat: add abilty to attach song to songbook
This commit is contained in:
1 parent
001a0d6ef8
commit
e3115df0bd
3 files changed
+46
-14
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 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user