Add option for manual input during fetch #219

Merged
wojtek merged 9 commits from 188---add-option-for-manual-input-during-fetch into main 2024-09-23 22:40:25 +02:00
3 changed files with 15 additions and 15 deletions
Showing only changes of commit 3fb7d719d1 - Show all commits

View File

@ -75,7 +75,7 @@ impl<'a> LookupArtistRequest<'a> {
pub struct LookupArtistResponse {
pub id: Mbid,
pub name: ArtistId,
pub sort: Option<ArtistId>,
pub sort_name: ArtistId,
pub disambiguation: Option<String>,
pub release_groups: Vec<LookupArtistResponseReleaseGroup>,
}
@ -92,13 +92,10 @@ struct DeserializeLookupArtistResponse {
impl From<DeserializeLookupArtistResponse> for LookupArtistResponse {
fn from(value: DeserializeLookupArtistResponse) -> Self {
let sort: Option<ArtistId> = Some(value.sort_name)
.filter(|s| s != &value.name)
.map(Into::into);
LookupArtistResponse {
id: value.id.into(),
name: value.name.into(),
sort,
sort_name: value.sort_name.into(),
disambiguation: value.disambiguation,
release_groups: value
.release_groups
@ -229,7 +226,7 @@ mod tests {
let response = LookupArtistResponse {
id: de_id.0,
name: de_name.into(),
sort: Some(de_sort_name.into()),
sort_name: de_sort_name.into(),
disambiguation: de_disambiguation,
release_groups: vec![release_group],
};

View File

@ -50,7 +50,7 @@ pub struct SearchArtistResponseArtist {
pub score: u8,
pub id: Mbid,
pub name: ArtistId,
pub sort: Option<ArtistId>,
pub sort_name: ArtistId,
pub disambiguation: Option<String>,
}
@ -66,14 +66,11 @@ struct DeserializeSearchArtistResponseArtist {
impl From<DeserializeSearchArtistResponseArtist> for SearchArtistResponseArtist {
fn from(value: DeserializeSearchArtistResponseArtist) -> Self {
let sort: Option<ArtistId> = Some(value.sort_name)
.filter(|s| s != &value.name)
.map(Into::into);
SearchArtistResponseArtist {
score: value.score,
id: value.id.into(),
name: value.name.into(),
sort,
sort_name: value.sort_name.into(),
disambiguation: value.disambiguation,
}
}
@ -109,7 +106,7 @@ mod tests {
score: 67,
id: a.id.0,
name: a.name.clone().into(),
sort: Some(a.sort_name).filter(|sn| sn != &a.name).map(Into::into),
sort_name: a.sort_name.clone().into(),
disambiguation: a.disambiguation,
})
.collect(),

View File

@ -5,7 +5,7 @@ use std::collections::HashMap;
use musichoard::{
collection::{
album::{AlbumDate, AlbumMeta, AlbumSeq},
artist::ArtistMeta,
artist::{ArtistId, ArtistMeta},
musicbrainz::Mbid,
},
external::musicbrainz::{
@ -93,10 +93,13 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
}
fn from_lookup_artist_response(entity: LookupArtistResponse) -> Lookup<ArtistMeta> {
let sort: Option<ArtistId> = Some(entity.sort_name)
.filter(|s| s != &entity.name)
.map(Into::into);
Lookup {
item: ArtistMeta {
id: entity.name,
sort: entity.sort.map(Into::into),
sort,
musicbrainz: Some(entity.id.into()),
properties: HashMap::new(),
},
@ -119,11 +122,14 @@ fn from_lookup_release_group_response(entity: LookupReleaseGroupResponse) -> Loo
}
fn from_search_artist_response_artist(entity: SearchArtistResponseArtist) -> Match<ArtistMeta> {
let sort: Option<ArtistId> = Some(entity.sort_name)
.filter(|s| s != &entity.name)
.map(Into::into);
Match {
score: entity.score,
item: ArtistMeta {
id: entity.name,
sort: entity.sort.map(Into::into),
sort,
musicbrainz: Some(entity.id.into()),
properties: HashMap::new(),
},