Adding tracknumber, adding sorting
Some checks failed
Music Collection CI Workflow / test (./frontend) (push) Successful in 36s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/msuic-collection-backend, ./backend) (push) Has been skipped
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Has been skipped
Music Collection CI Workflow / deploy (push) Has been skipped
Music Collection CI Workflow / test (./backend) (push) Failing after 29s

This commit is contained in:
Phill Pover 2025-04-06 23:14:48 +01:00
parent 13ec515d97
commit fa3daa831f
7 changed files with 22 additions and 4 deletions

View File

@ -13,7 +13,11 @@ export class AlbumService {
) {}
findAll(): Promise<Album[]> {
return this.albumRepository.find();
return this.albumRepository.find({
order: {
artist: "ASC"
}
});
}
findOneById(id: number): Promise<Album | null> {

View File

@ -1,5 +1,6 @@
export class CreateSongDto {
title: string;
duration: number;
trackNumber: number;
albumId: number;
}

View File

@ -2,5 +2,6 @@ export class UpdateSongDto {
id: number;
title: string;
duration: number;
trackNumber: number;
albumId: number;
}

View File

@ -12,6 +12,9 @@ export class Song {
@Column()
duration: number
@Column
trackNumber: number
@ManyToOne(() => Album, (album) => album.songs)
album: Album
}

View File

@ -13,7 +13,11 @@ export class SongService {
) {}
findAll(): Promise<Song[]> {
return this.songRepository.find();
return this.songRepository.find({
order: {
trackNumber: "ASC"
}
});
}
findOneById(id: number): Promise<Song | null> {
@ -23,7 +27,8 @@ export class SongService {
async create(createSongDto: CreateSongDto): Promise<number> {
const song = this.songRepository.create({
title: createSongDto.title,
duration: createSongDto.duration
duration: createSongDto.duration,
trackNumber: createSongDto.trackNumber
});
const savedSong = await this.songRepository.save(song);
return savedSong.id;
@ -37,7 +42,8 @@ export class SongService {
await this.songRepository.update({ id: updateSongDto.id }, {
title: updateSongDto.title,
duration: updateSongDto.duration
duration: updateSongDto.duration,
trackNumber: createSongDto.trackNumber
});
return "Song updated successfully";
} else {

View File

@ -58,6 +58,7 @@ export default function Page() {
<table className="u-full-width">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Duration</th>
</tr>
@ -65,6 +66,7 @@ export default function Page() {
<tbody>
{album.songs.map((song: Song) => (
<tr key={song.id}>
<td>{song.trackNumber}</td>
<td>{song.title}</td>
<td>{TimeUtils.fancyTimeFormat(song.duration)}</td>
</tr>

View File

@ -4,5 +4,6 @@ export interface Song {
id: number;
title: string;
duration: number;
trackNumber: number;
album: Album;
}