Fixing form submission
All checks were successful
Music Collection CI Workflow / test (./backend) (push) Successful in 21s
Music Collection CI Workflow / test (./frontend) (push) Successful in 20s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/msuic-collection-backend, ./backend) (push) Successful in 48s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Successful in 1m17s
Music Collection CI Workflow / deploy (push) Successful in 22s

This commit is contained in:
Phill Pover 2025-04-06 18:44:00 +01:00
parent 5088de6015
commit 60d30bd1d3
2 changed files with 31 additions and 11 deletions

View File

@ -11,14 +11,34 @@ export async function createAlbum(formData: FormData) {
title: title, title: title,
artist: artist, artist: artist,
genre: genre, genre: genre,
}), })
});
}
export async function updateAlbum(formData: FormData) {
const id = formData.get('id');
const title = formData.get('title');
const artist = formData.get('artist');
const genre = formData.get('genre');
return await fetch("https://api.anatid.net/album", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: id,
title: title,
artist: artist,
genre: genre,
})
});
}
export async function deleteAlbum(formData: FormData) {
const id = formData.get('id');
return await fetch("https://api.anatid.net/album", {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: id,
})
}); });
} }
//
// export async function updateAlbum(formData: FormData) {
//
// }
//
// export async function deleteAlbum(formData: FormData) {
//
// }

View File

@ -21,13 +21,13 @@ export default function Page() {
setAlbums(data); setAlbums(data);
} }
fetchAlbums(); fetchAlbums();
}, []); });
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => { const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault(); event.preventDefault();
const formData = new FormData(event.currentTarget); const formData = new FormData(event.currentTarget);
const response = await createAlbum(formData) const response = await createAlbum(formData);
const data = response.json(); const data = response.json();
handleClose(); handleClose();
return data; return data;