Fixing update song
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Successful in 29s
Music Collection CI Workflow / test (./frontend) (push) Successful in 36s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Successful in 50s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Failing after 1m34s
Music Collection CI Workflow / deploy (push) Has been skipped

This commit is contained in:
Phill Pover 2025-04-07 05:30:29 +01:00
parent e11c22f554
commit d66d476acb
5 changed files with 8 additions and 12 deletions

View File

@ -12,27 +12,23 @@ export class AlbumController {
@Get() @Get()
findAll(): Promise<Album[]> { findAll(): Promise<Album[]> {
console.log("AlbumController findAll")
return this.albumService.findAll(); return this.albumService.findAll();
} }
@Get(':id') @Get(':id')
findOneById(@Param('id') id: number): Promise<Album | null> { findOneById(@Param('id') id: number): Promise<Album | null> {
console.log("AlbumController findOnyById: ",id);
return this.albumService.findOneById(id); return this.albumService.findOneById(id);
} }
@Post() @Post()
@UsePipes(new ValidationPipe({ transform: true })) @UsePipes(new ValidationPipe({ transform: true }))
async create(@Body() createAlbumDto: CreateAlbumDto): Promise<Album | null> { async create(@Body() createAlbumDto: CreateAlbumDto): Promise<Album | null> {
console.log("AlbumController create: ",createAlbumDto);
return this.albumService.create(createAlbumDto); return this.albumService.create(createAlbumDto);
} }
@Put(':id') @Put(':id')
@UsePipes(new ValidationPipe({ transform: true })) @UsePipes(new ValidationPipe({ transform: true }))
async update(@Param('id') id: number, @Body() updateAlbumDto: UpdateAlbumDto): Promise<Album | null> { async update(@Param('id') id: number, @Body() updateAlbumDto: UpdateAlbumDto): Promise<Album | null> {
console.log("AlbumController update: ",id,updateAlbumDto);
return this.albumService.update(id, updateAlbumDto); return this.albumService.update(id, updateAlbumDto);
} }

View File

@ -43,23 +43,20 @@ export class AlbumService {
} }
async update(id: number, updateAlbumDto: UpdateAlbumDto): Promise<Album | null> { async update(id: number, updateAlbumDto: UpdateAlbumDto): Promise<Album | null> {
console.log(id, updateAlbumDto);
if (id == updateAlbumDto.id) { if (id == updateAlbumDto.id) {
const albumToUpdate = await this.albumRepository.findOneBy({ id: updateAlbumDto.id }); const albumToUpdate = await this.albumRepository.findOneBy({ id: updateAlbumDto.id });
if (!albumToUpdate) { if (!albumToUpdate) {
console.log("Didn't find album: ", id); console.error("AlbumService: update: Didn't find album: ", id);
return null; return null;
} }
albumToUpdate.title = updateAlbumDto.title; albumToUpdate.title = updateAlbumDto.title;
albumToUpdate.artist = updateAlbumDto.artist; albumToUpdate.artist = updateAlbumDto.artist;
albumToUpdate.genre = updateAlbumDto.genre; albumToUpdate.genre = updateAlbumDto.genre;
console.log("Saving album:", albumToUpdate);
const savedAlbum = await this.albumRepository.save(albumToUpdate); const savedAlbum = await this.albumRepository.save(albumToUpdate);
console.log("Saved album: ", savedAlbum);
return savedAlbum; return savedAlbum;
} else { } else {
console.log("ids don't match", id, updateAlbumDto); console.error("AlbumService: update: IDs do not match", id, updateAlbumDto);
return null; return null;
} }
} }

View File

@ -4,7 +4,7 @@ import { AppModule } from './app.module';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule, { const app = await NestFactory.create(AppModule, {
logger: ['error', 'log', 'warn'], logger: ['error', 'warn'],
}); });
app.enableCors({ app.enableCors({
origin: ['https://music.anatid.net'], origin: ['https://music.anatid.net'],

View File

@ -46,8 +46,10 @@ export class SongService {
if (id == updateSongDto.id) { if (id == updateSongDto.id) {
const album = await this.albumRepository.findOneBy({id: updateSongDto.albumId}); const album = await this.albumRepository.findOneBy({id: updateSongDto.albumId});
const songToUpdate = await this.songRepository.findOneBy({ id: updateSongDto.id }); const songToUpdate = await this.songRepository.findOneBy({ id: updateSongDto.id });
if (!songToUpdate || !album) if (!songToUpdate || !album) {
console.error("SongService: update: Song or Album not found");
return null; return null;
}
songToUpdate.id = updateSongDto.id; songToUpdate.id = updateSongDto.id;
songToUpdate.title = updateSongDto.title; songToUpdate.title = updateSongDto.title;
@ -57,6 +59,7 @@ export class SongService {
const song = await this.songRepository.save(songToUpdate); const song = await this.songRepository.save(songToUpdate);
return song; return song;
} else { } else {
console.error("SongService: update: IDs do not match");
return null; return null;
} }
} }

View File

@ -150,7 +150,7 @@ export async function updateSong(formData: FormData) {
const title = formData.get('title'); const title = formData.get('title');
const duration = formData.get('duration'); const duration = formData.get('duration');
const trackNumber = formData.get('trackNumber'); const trackNumber = formData.get('trackNumber');
return fetch(`https://api.anatid.net/song/${id}`, { return fetch(`https://api.anatid.net/song/${album-id}`, {
method: "PUT", method: "PUT",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({