diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index ccbd707..d9b16f4 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -5,6 +5,7 @@ use std::{ use crate::core::collection::{ merge::{Merge, MergeSorted, WithId}, + musicbrainz::MusicBrainz, track::{Track, TrackFormat}, }; @@ -14,6 +15,7 @@ pub struct Album { pub id: AlbumId, pub date: AlbumDate, pub seq: AlbumSeq, + pub musicbrainz: Option, pub tracks: Vec, } @@ -50,6 +52,16 @@ impl AlbumDate { } } +impl From for AlbumDate { + fn from(year: u32) -> Self { + AlbumDate { + year, + month: AlbumMonth::default(), + day: 0, + } + } +} + #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Ord, Eq, Hash)] pub enum AlbumMonth { @@ -115,6 +127,16 @@ impl AlbumStatus { } impl Album { + pub fn new, Date: Into>(id: Id, date: Date) -> Self { + Album { + id: id.into(), + date: date.into(), + seq: AlbumSeq::default(), + musicbrainz: None, + tracks: vec![], + } + } + pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &AlbumId) { (&self.date, &self.seq, &self.id) } @@ -209,22 +231,14 @@ mod tests { let album_id_1 = AlbumId { title: String::from("album z"), }; - let album_1 = Album { - id: album_id_1, - date: date.clone(), - seq: AlbumSeq(1), - tracks: vec![], - }; + let mut album_1 = Album::new(album_id_1, date.clone()); + album_1.set_seq(AlbumSeq(1)); let album_id_2 = AlbumId { title: String::from("album a"), }; - let album_2 = Album { - id: album_id_2, - date: date.clone(), - seq: AlbumSeq(2), - tracks: vec![], - }; + let mut album_2 = Album::new(album_id_2, date.clone()); + album_2.set_seq(AlbumSeq(2)); assert_ne!(album_1, album_2); assert!(album_1 < album_2); @@ -232,12 +246,7 @@ mod tests { #[test] fn set_clear_seq() { - let mut album = Album { - id: "an album".into(), - date: AlbumDate::default(), - seq: AlbumSeq::default(), - tracks: vec![], - }; + let mut album = Album::new("An album", AlbumDate::default()); assert_eq!(album.seq, AlbumSeq(0)); diff --git a/src/core/collection/artist.rs b/src/core/collection/artist.rs index ae5e00a..2653e65 100644 --- a/src/core/collection/artist.rs +++ b/src/core/collection/artist.rs @@ -36,7 +36,7 @@ pub struct ArtistId { impl Artist { /// Create new [`Artist`] with the given [`ArtistId`]. - pub fn new>(id: ID) -> Self { + pub fn new>(id: Id) -> Self { Artist { id: id.into(), sort: None, diff --git a/src/core/database/serde/deserialize.rs b/src/core/database/serde/deserialize.rs index cc4a64a..7b26529 100644 --- a/src/core/database/serde/deserialize.rs +++ b/src/core/database/serde/deserialize.rs @@ -64,6 +64,7 @@ impl From for Album { id: AlbumId { title: album.title }, date: AlbumDate::default(), seq: AlbumSeq(album.seq), + musicbrainz: None, tracks: vec![], } } diff --git a/src/core/musichoard/musichoard.rs b/src/core/musichoard/musichoard.rs index 7834d43..17dcec7 100644 --- a/src/core/musichoard/musichoard.rs +++ b/src/core/musichoard/musichoard.rs @@ -141,12 +141,11 @@ impl MusicHoard { .find(|album| album.id == album_id) { Some(album) => album.tracks.push(track), - None => artist.albums.push(Album { - id: album_id, - date: album_date, - seq: AlbumSeq(0), - tracks: vec![track], - }), + None => { + let mut album = Album::new(album_id, album_date); + album.tracks.push(track); + artist.albums.push(album); + } } } @@ -748,12 +747,9 @@ mod tests { let album_id_2 = AlbumId::new("another album"); let mut database_result = vec![Artist::new(artist_id.clone())]; - database_result[0].albums.push(Album { - id: album_id.clone(), - date: AlbumDate::default(), - seq: AlbumSeq::default(), - tracks: vec![], - }); + database_result[0] + .albums + .push(Album::new(album_id.clone(), AlbumDate::default())); database .expect_load() diff --git a/src/tests.rs b/src/tests.rs index c54bb6e..305261c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -19,6 +19,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -79,6 +80,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -124,6 +126,7 @@ macro_rules! library_collection { day: 6, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -162,6 +165,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -200,6 +204,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -238,6 +243,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -288,6 +294,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -326,6 +333,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -374,6 +382,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -412,6 +421,7 @@ macro_rules! library_collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 3959a03..119c15c 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -744,7 +744,7 @@ impl IUi for Ui { #[cfg(test)] mod tests { - use musichoard::collection::{album::AlbumId, artist::ArtistId}; + use musichoard::collection::artist::ArtistId; use crate::tui::{ app::{AppPublic, AppPublicInner, Delta}, @@ -868,12 +868,9 @@ mod tests { #[test] fn empty_album() { let mut artists: Vec = vec![Artist::new(ArtistId::new("An artist"))]; - artists[0].albums.push(Album { - id: AlbumId::new("An album"), - date: AlbumDate::default(), - seq: AlbumSeq::default(), - tracks: vec![], - }); + artists[0] + .albums + .push(Album::new("An album", AlbumDate::default())); let mut selection = Selection::new(&artists); draw_test_suite(&artists, &mut selection); diff --git a/tests/testlib.rs b/tests/testlib.rs index dc708da..81ebb54 100644 --- a/tests/testlib.rs +++ b/tests/testlib.rs @@ -42,6 +42,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -227,6 +228,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -306,6 +308,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -469,6 +472,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -622,6 +626,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -645,6 +650,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -753,6 +759,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId { @@ -854,6 +861,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { day: 0, }, seq: AlbumSeq(0), + musicbrainz: None, tracks: vec![ Track { id: TrackId {