From 085f76bbcb07ce06daebb9cce26ec5f56378b690 Mon Sep 17 00:00:00 2001 From: Phill Pover Date: Mon, 7 Apr 2025 12:51:20 +0100 Subject: [PATCH] Cleanup --- README.md | 3 ++- frontend/src/app/album/[id]/page.tsx | 24 +++++++++++++++++------- frontend/src/app/album/page.tsx | 8 ++++---- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3471364..ddc92dc 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Swagger Docs are available at [https://api.anatid.net/api](https://api.anatid.ne The frontend and backend are built as Docker Images, running with Docker Compose behind a Swag based reverse proxy to enable SSL provided by LetsEncrypt, with the API suppored by a Postgres database for persistence. +``` services: music-collection-frontend: image: git.anatid.net/tabris/music-collection-frontend:main @@ -90,7 +91,7 @@ networks: external: false frontend: external: false - +``` ## Repository The code can be found at [https://git.anatid.net/tabris/music-collection](https://git.anatid.net/tabris/music-collection), and is continuously deployed to the Docker network on commit by a pipeline Runner. diff --git a/frontend/src/app/album/[id]/page.tsx b/frontend/src/app/album/[id]/page.tsx index 023aeae..20ce14a 100644 --- a/frontend/src/app/album/[id]/page.tsx +++ b/frontend/src/app/album/[id]/page.tsx @@ -51,17 +51,27 @@ export default function Page() { const formData = new FormData(event.currentTarget); try { if (formData.get('id') == "") { - await createSong(formData); - handleSnackbar(`Successfully created Song with ID ${formData.get("id")}`, true); + await createSong(formData).then(response => { + if (response.ok) { + handleSnackbar(`Successfully created Song with ID ${formData.get("id")}: ${JSON.stringify(response)}`, true); + } + handleSnackbar(`Failed to create Song with ID ${formData.get("id")}: ${JSON.stringify(response)}`, false); + }) + .catch(error => {handleSnackbar(`Failed to create Song with ID ${formData.get("id")}: ${JSON.stringify(error)}`, false);}); } else { - await updateSong(formData); - handleSnackbar(`Successfully updated Song with ID ${formData.get("id")}`, true); + await updateSong(formData).then(response => { + if (response.ok) { + handleSnackbar(`Successfully created Song with ID ${formData.get("id")}: ${JSON.stringify(response)}`, true); + } + handleSnackbar(`Failed to create Song with ID ${formData.get("id")}: ${JSON.stringify(response)}`, false); + }) + .catch(error => {handleSnackbar(`Failed to create Song with ID ${formData.get("id")}: ${JSON.stringify(error)}`, false);}); } revalidateAlbum(); const data = await getAlbum(parseInt(albumId)); setAlbum(data); } catch (error) { - handleSnackbar(`Error creating Song: ${error}`, false); + handleSnackbar(`Error creating Song: ${JSON.stringify(error)}`, false); } } @@ -90,7 +100,7 @@ export default function Page() { setFormSongTrackNumber(data.trackNumber); handleShow(); } catch (error) { - handleSnackbar(`Error getting song with ID ${songId}: ${error}`, false); + handleSnackbar(`Error getting song with ID ${songId}: ${JSON.stringify(error)}`, false); } } else { handleSnackbar(`Couldn't get ID of clicked element`, false); @@ -104,7 +114,7 @@ export default function Page() { try { await deleteSong(parseInt(songId)); } catch (error) { - handleSnackbar(`Error deleting song with ID ${songId}: ${error}`, false); + handleSnackbar(`Error deleting song with ID ${songId}: ${JSON.stringify(error)}`, false); } revalidateAlbum(); const data = await getAlbum(parseInt(albumId)); diff --git a/frontend/src/app/album/page.tsx b/frontend/src/app/album/page.tsx index 6ba1bb2..1a20e4b 100644 --- a/frontend/src/app/album/page.tsx +++ b/frontend/src/app/album/page.tsx @@ -33,7 +33,7 @@ export default function Page() { const data = await getAlbums(); setAlbums(data); } catch (error) { - handleSnackbar(`Error getting albums: ${error}`, false); + handleSnackbar(`Error getting albums: ${JSON.stringify(error)}`, false); } } fetchAlbums(); @@ -68,7 +68,7 @@ export default function Page() { const data = await getAlbums(); setAlbums(data); } catch (error) { - handleSnackbar(`Error creating Album: ${error}`, false); + handleSnackbar(`Error creating Album: ${JSON.stringify(error)}`, false); } } @@ -95,7 +95,7 @@ export default function Page() { setFormAlbumGenre(data.genre); handleShow(); } catch (error) { - handleSnackbar(`Error getting Album with ID ${id}: ${error}`, false); + handleSnackbar(`Error getting Album with ID ${id}: ${JSON.stringify(error)}`, false); } } else { handleSnackbar(`Couldn't get ID of clicked element`, false); @@ -109,7 +109,7 @@ export default function Page() { await deleteAlbum(parseInt(id)); handleSnackbar(`Successfully deleted Album with ID ${id}`, true); } catch (error) { - handleSnackbar(`Error deleting Album with ID ${id}: ${error}`, false); + handleSnackbar(`Error deleting Album with ID ${id}: ${JSON.stringify(error)}`, false); } revalidateAlbums(); const data = await getAlbums();