Nits
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 2m0s
Cargo CI / Lint (pull_request) Successful in 1m7s

This commit is contained in:
Wojciech Kozlowski 2024-09-22 16:23:00 +02:00
parent 7c381bece0
commit 3fb7d719d1
3 changed files with 15 additions and 15 deletions

View File

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

View File

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

View File

@ -5,7 +5,7 @@ use std::collections::HashMap;
use musichoard::{ use musichoard::{
collection::{ collection::{
album::{AlbumDate, AlbumMeta, AlbumSeq}, album::{AlbumDate, AlbumMeta, AlbumSeq},
artist::ArtistMeta, artist::{ArtistId, ArtistMeta},
musicbrainz::Mbid, musicbrainz::Mbid,
}, },
external::musicbrainz::{ external::musicbrainz::{
@ -93,10 +93,13 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
} }
fn from_lookup_artist_response(entity: LookupArtistResponse) -> Lookup<ArtistMeta> { 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 { Lookup {
item: ArtistMeta { item: ArtistMeta {
id: entity.name, id: entity.name,
sort: entity.sort.map(Into::into), sort,
musicbrainz: Some(entity.id.into()), musicbrainz: Some(entity.id.into()),
properties: HashMap::new(), 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> { 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 { Match {
score: entity.score, score: entity.score,
item: ArtistMeta { item: ArtistMeta {
id: entity.name, id: entity.name,
sort: entity.sort.map(Into::into), sort,
musicbrainz: Some(entity.id.into()), musicbrainz: Some(entity.id.into()),
properties: HashMap::new(), properties: HashMap::new(),
}, },