diff --git a/backend/src/album/album.controller.ts b/backend/src/album/album.controller.ts index 48de48c..2eb97c1 100644 --- a/backend/src/album/album.controller.ts +++ b/backend/src/album/album.controller.ts @@ -25,7 +25,7 @@ export class AlbumController { } @Put() - async update(@Body() updateAlbumDto: UpdateAlbumDto): Promise { + async update(@Param('id') id: number, @Body() updateAlbumDto: UpdateAlbumDto): Promise { return this.albumService.update(updateAlbumDto); } diff --git a/backend/src/album/album.service.ts b/backend/src/album/album.service.ts index 12cf014..9b208ba 100644 --- a/backend/src/album/album.service.ts +++ b/backend/src/album/album.service.ts @@ -37,17 +37,21 @@ export class AlbumService { return savedAlbum.id; } - async update(updateAlbumDto: UpdateAlbumDto): Promise { - const album = this.albumRepository.findOneBy({ id: updateAlbumDto.id }); - if (!album) - return "Album not found"; + async update(id: number, updateAlbumDto: UpdateAlbumDto): Promise { + if (id === updateAlbumDto.id) { + const album = this.albumRepository.findOneBy({ id: updateAlbumDto.id }); + if (!album) + return "Album not found"; - await this.albumRepository.update({ id: updateAlbumDto.id }, { - title: updateAlbumDto.title, - artist: updateAlbumDto.artist, - genre: updateAlbumDto.genre - }); - return "Album updated successfully"; + await this.albumRepository.update({ id: updateAlbumDto.id }, { + title: updateAlbumDto.title, + artist: updateAlbumDto.artist, + genre: updateAlbumDto.genre + }); + return "Album updated successfully"; + } else { + return "Album ID does not match posted data"; + } } async remove(id: number): Promise { diff --git a/frontend/src/app/actions.tsx b/frontend/src/app/actions.tsx index 3e5018b..7438edc 100644 --- a/frontend/src/app/actions.tsx +++ b/frontend/src/app/actions.tsx @@ -1,7 +1,10 @@ 'use server' export async function getAlbums() { - return fetch('https://api.anatid.net/album').then(response => { + return fetch('https://api.anatid.net/album', { + method: "GET", + headers: { "Content-Type": "application/json" }, + }).then(response => { return response.json(); }); } @@ -37,7 +40,7 @@ export async function updateAlbum(formData: FormData) { const title = formData.get('title'); const artist = formData.get('artist'); const genre = formData.get('genre'); - return fetch("https://api.anatid.net/album", { + return fetch(`https://api.anatid.net/album/${id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -52,7 +55,7 @@ export async function updateAlbum(formData: FormData) { } export async function deleteAlbum(id: number) { - return fetch("https://api.anatid.net/album", { + return fetch(`https://api.anatid.net/album/${id}`, { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -64,7 +67,12 @@ export async function deleteAlbum(id: number) { } export async function getSongs() { - return fetch("https://api.anatid.net/song/"); + return fetch("https://api.anatid.net/song/", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }).then(response => { + return response.json(); + }); } export async function getSong(id: number) { @@ -98,7 +106,7 @@ export async function updateSong(formData: FormData) { const albumId = formData.get('album-id'); const title = formData.get('title'); const duration = formData.get('duration'); - return fetch("https://api.anatid.net/song", { + return fetch(`https://api.anatid.net/song/${id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -113,12 +121,9 @@ export async function updateSong(formData: FormData) { } export async function deleteSong(id: number) { - return fetch("https://api.anatid.net/song", { + return fetch(`https://api.anatid.net/song/${id}`, { method: "DELETE", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - id: id, - }) + headers: { "Content-Type": "application/json" } }).then(response => { return response.json(); });