Integrate browse API into TUI MB daemon #230

Merged
wojtek merged 15 commits from 160---provide-a-keyboard-shortcut-to-pull-all-release-groups-of-an-artist into main 2024-10-06 15:32:46 +02:00
3 changed files with 28 additions and 34 deletions
Showing only changes of commit 17d94e59f1 - Show all commits

View File

@ -49,13 +49,10 @@ impl<T> MbRefOption<T> {
pub fn or(self, optb: MbRefOption<T>) -> MbRefOption<T> { pub fn or(self, optb: MbRefOption<T>) -> MbRefOption<T> {
match self { match self {
opta @ MbRefOption::Some(_) => opta, opta @ MbRefOption::Some(_) => opta,
opta @ MbRefOption::CannotHaveMbid => { opta @ MbRefOption::CannotHaveMbid => match optb {
if matches!(optb, MbRefOption::Some(_)) { MbRefOption::Some(_) => optb,
optb MbRefOption::CannotHaveMbid | MbRefOption::None => opta,
} else { },
opta
}
}
MbRefOption::None => optb, MbRefOption::None => optb,
} }
} }

View File

@ -395,8 +395,10 @@ mod tests {
match matches_info { match matches_info {
EntityMatches::Album(_) => { EntityMatches::Album(_) => {
let album_id = AlbumId::new("Album"); let album_id = AlbumId::new("Album");
let mut info = album_meta(album_id.clone()).info; let info = AlbumInfo {
info.musicbrainz = MbRefOption::CannotHaveMbid; musicbrainz: MbRefOption::CannotHaveMbid,
..Default::default()
};
music_hoard music_hoard
.expect_merge_album_info() .expect_merge_album_info()
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info)) .with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
@ -404,8 +406,10 @@ mod tests {
.return_once(|_, _, _| Ok(())); .return_once(|_, _, _| Ok(()));
} }
EntityMatches::Artist(_) => { EntityMatches::Artist(_) => {
let mut info = artist_meta().info; let info = ArtistInfo {
info.musicbrainz = MbRefOption::CannotHaveMbid; musicbrainz: MbRefOption::CannotHaveMbid,
..Default::default()
};
music_hoard music_hoard
.expect_merge_artist_info() .expect_merge_artist_info()
.with(eq(artist_id.clone()), eq(info)) .with(eq(artist_id.clone()), eq(info))

View File

@ -252,10 +252,6 @@ impl JobInstance {
api_params: &MbParams, api_params: &MbParams,
paging: &mut Option<PageSettings>, paging: &mut Option<PageSettings>,
) -> Result<(), JobInstanceError> { ) -> Result<(), JobInstanceError> {
if paging.is_none() {
*paging = Some(PageSettings::with_max_limit());
}
let result = match api_params { let result = match api_params {
MbParams::Lookup(lookup) => match lookup { MbParams::Lookup(lookup) => match lookup {
LookupParams::Artist(p) => musicbrainz LookupParams::Artist(p) => musicbrainz
@ -280,15 +276,24 @@ impl JobInstance {
} }
.map(MbReturn::Match), .map(MbReturn::Match),
MbParams::Browse(browse) => match browse { MbParams::Browse(browse) => match browse {
BrowseParams::ReleaseGroup(params) => musicbrainz BrowseParams::ReleaseGroup(params) => {
Self::init_paging_if_none(paging);
musicbrainz
.browse_release_group(&params.artist, paging) .browse_release_group(&params.artist, paging)
.map(|rv| EntityList::Album(rv.into_iter().map(|rg| rg.entity).collect())), .map(|rv| EntityList::Album(rv.into_iter().map(|rg| rg.entity).collect()))
}
} }
.map(MbReturn::Fetch), .map(MbReturn::Fetch),
}; };
Self::return_result(result_sender, event_sender, result) Self::return_result(result_sender, event_sender, result)
} }
fn init_paging_if_none(paging: &mut Option<PageSettings>) {
if paging.is_none() {
*paging = Some(PageSettings::with_max_limit());
}
}
fn return_result( fn return_result(
result_sender: &mut ResultSender, result_sender: &mut ResultSender,
event_sender: &mut dyn IFetchCompleteEventSender, event_sender: &mut dyn IFetchCompleteEventSender,
@ -757,24 +762,12 @@ mod tests {
let artist_id = album_artist_id(); let artist_id = album_artist_id();
let result = result_receiver.try_recv().unwrap(); let result = result_receiver.try_recv().unwrap();
assert_eq!( let matches = EntityMatches::album_search(artist_id.clone(), album_1.id, matches_1);
result, assert_eq!(result, Ok(MbReturn::Match(matches)));
Ok(MbReturn::Match(EntityMatches::album_search(
artist_id.clone(),
album_1.id,
matches_1
)))
);
let result = result_receiver.try_recv().unwrap(); let result = result_receiver.try_recv().unwrap();
assert_eq!( let matches = EntityMatches::album_search(artist_id.clone(), album_4.id, matches_4);
result, assert_eq!(result, Ok(MbReturn::Match(matches)));
Ok(MbReturn::Match(EntityMatches::album_search(
artist_id.clone(),
album_4.id,
matches_4
)))
);
} }
#[test] #[test]