use super::{Cursors, ExternalUrls, Followers, Image, ItemType};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Artist {
pub external_urls: ExternalUrls,
pub followers: Followers,
pub genres: Vec<String>,
pub href: String,
pub id: String,
pub images: Vec<Image>,
pub name: String,
pub popularity: u8,
#[serde(rename = "type")]
pub type_: ItemType,
pub uri: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SimplifiedArtist {
pub external_urls: ExternalUrls,
pub href: String,
pub id: String,
pub name: String,
#[serde(rename = "type")]
pub type_: ItemType,
pub uri: String,
}
impl From<Artist> for SimplifiedArtist {
fn from(artist: Artist) -> Self {
Self {
external_urls: artist.external_urls,
href: artist.href,
id: artist.id,
name: artist.name,
type_: artist.type_,
uri: artist.uri,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Artists {
pub artists: Vec<Option<Artist>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FollowedArtist {
pub href: String,
pub limit: usize,
pub next: Option<String>,
pub cursors: Cursors,
pub total: usize,
pub items: Vec<Artist>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FollowedArtists {
pub artists: FollowedArtist,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn artist() {
let json = r#"
{
"external_urls": {
"spotify": "string"
},
"followers": {
"href": "string",
"total": 0
},
"genres": ["Prog rock", "Grunge"],
"href": "string",
"id": "string",
"images": [
{
"url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
"height": 300,
"width": 300
}
],
"name": "string",
"popularity": 0,
"type": "artist",
"uri": "string"
}
"#;
crate::test::assert_deserialized!(Artist, json);
}
#[test]
fn simplified_artist() {
let json = r#"
{
"external_urls": {
"spotify": "string"
},
"href": "string",
"id": "string",
"name": "string",
"type": "artist",
"uri": "string"
}
"#;
crate::test::assert_deserialized!(SimplifiedArtist, json);
}
}