More ergonomic code
This commit is contained in:
parent
5e4baf7191
commit
493b8a3928
@ -40,18 +40,11 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
|||||||
) -> Result<BrowseReleaseGroupResponse, Error> {
|
) -> Result<BrowseReleaseGroupResponse, Error> {
|
||||||
let entity = &request.entity;
|
let entity = &request.entity;
|
||||||
let mbid = request.mbid.uuid().as_hyphenated();
|
let mbid = request.mbid.uuid().as_hyphenated();
|
||||||
let status = match request.release_group_status {
|
let status = request
|
||||||
Some(ref value) => {
|
.release_group_status
|
||||||
let value_str = match value {
|
.as_ref()
|
||||||
BrowseReleaseGroupRequestReleaseGroupStatus::WebsiteDefault => {
|
.map(|s| format!("&release-group-status={s}"))
|
||||||
"website-default"
|
.unwrap_or_default();
|
||||||
}
|
|
||||||
BrowseReleaseGroupRequestReleaseGroupStatus::All => "all",
|
|
||||||
};
|
|
||||||
format!("&release-group-status={value_str}")
|
|
||||||
}
|
|
||||||
None => String::from(""),
|
|
||||||
};
|
|
||||||
let page = ApiDisplay::format_page_settings(paging);
|
let page = ApiDisplay::format_page_settings(paging);
|
||||||
|
|
||||||
let url = format!("{MB_BASE_URL}/release-group?{entity}={mbid}{status}{page}");
|
let url = format!("{MB_BASE_URL}/release-group?{entity}={mbid}{status}{page}");
|
||||||
@ -71,15 +64,24 @@ enum BrowseReleaseGroupRequestEntity {
|
|||||||
Artist,
|
Artist,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for BrowseReleaseGroupRequestEntity {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Artist => write!(f, "artist"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum BrowseReleaseGroupRequestReleaseGroupStatus {
|
enum BrowseReleaseGroupRequestReleaseGroupStatus {
|
||||||
WebsiteDefault,
|
WebsiteDefault,
|
||||||
All,
|
All,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for BrowseReleaseGroupRequestEntity {
|
impl fmt::Display for BrowseReleaseGroupRequestReleaseGroupStatus {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
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 =
|
self.release_group_status =
|
||||||
Some(BrowseReleaseGroupRequestReleaseGroupStatus::WebsiteDefault);
|
Some(BrowseReleaseGroupRequestReleaseGroupStatus::WebsiteDefault);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status_all(mut self) -> Self {
|
pub fn filter_status_all(mut self) -> Self {
|
||||||
self.release_group_status = Some(BrowseReleaseGroupRequestReleaseGroupStatus::All);
|
self.release_group_status = Some(BrowseReleaseGroupRequestReleaseGroupStatus::All);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
|
|||||||
artist: &Mbid,
|
artist: &Mbid,
|
||||||
paging: &mut Option<PageSettings>,
|
paging: &mut Option<PageSettings>,
|
||||||
) -> Result<Vec<Entity<AlbumMeta>>, Error> {
|
) -> Result<Vec<Entity<AlbumMeta>>, 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 page = paging.take().unwrap_or_default();
|
||||||
let mb_response = self.client.browse_release_group(&request, &page)?;
|
let mb_response = self.client.browse_release_group(&request, &page)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user