diff --git a/src/external/musicbrainz/api/browse.rs b/src/external/musicbrainz/api/browse.rs index 3a9d9cd..e662d0f 100644 --- a/src/external/musicbrainz/api/browse.rs +++ b/src/external/musicbrainz/api/browse.rs @@ -40,18 +40,11 @@ impl MusicBrainzClient { ) -> Result { let entity = &request.entity; let mbid = request.mbid.uuid().as_hyphenated(); - let status = match request.release_group_status { - Some(ref value) => { - let value_str = match value { - BrowseReleaseGroupRequestReleaseGroupStatus::WebsiteDefault => { - "website-default" - } - BrowseReleaseGroupRequestReleaseGroupStatus::All => "all", - }; - format!("&release-group-status={value_str}") - } - None => String::from(""), - }; + let status = request + .release_group_status + .as_ref() + .map(|s| format!("&release-group-status={s}")) + .unwrap_or_default(); let page = ApiDisplay::format_page_settings(paging); let url = format!("{MB_BASE_URL}/release-group?{entity}={mbid}{status}{page}"); @@ -71,15 +64,24 @@ enum BrowseReleaseGroupRequestEntity { Artist, } +impl fmt::Display for BrowseReleaseGroupRequestEntity { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Artist => write!(f, "artist"), + } + } +} + enum BrowseReleaseGroupRequestReleaseGroupStatus { WebsiteDefault, All, } -impl fmt::Display for BrowseReleaseGroupRequestEntity { +impl fmt::Display for BrowseReleaseGroupRequestReleaseGroupStatus { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - BrowseReleaseGroupRequestEntity::Artist => write!(f, "artist"), + Self::WebsiteDefault => write!(f, "website-default"), + Self::All => write!(f, "all"), } } } @@ -93,13 +95,13 @@ impl<'a> BrowseReleaseGroupRequest<'a> { } } - pub fn status_website_default(mut self) -> Self { + pub fn filter_status_website_default(mut self) -> Self { self.release_group_status = Some(BrowseReleaseGroupRequestReleaseGroupStatus::WebsiteDefault); self } - pub fn status_all(mut self) -> Self { + pub fn filter_status_all(mut self) -> Self { self.release_group_status = Some(BrowseReleaseGroupRequestReleaseGroupStatus::All); self } diff --git a/src/tui/lib/external/musicbrainz/api/mod.rs b/src/tui/lib/external/musicbrainz/api/mod.rs index acc1d4f..d648b8d 100644 --- a/src/tui/lib/external/musicbrainz/api/mod.rs +++ b/src/tui/lib/external/musicbrainz/api/mod.rs @@ -99,7 +99,7 @@ impl IMusicBrainz for MusicBrainz { artist: &Mbid, paging: &mut Option, ) -> Result>, Error> { - let request = BrowseReleaseGroupRequest::artist(artist).status_website_default(); + let request = BrowseReleaseGroupRequest::artist(artist).filter_status_website_default(); let page = paging.take().unwrap_or_default(); let mb_response = self.client.browse_release_group(&request, &page)?;