Merge branch '106-create-song-list-component' into 42-create-profile-page

This commit is contained in:
2024-11-01 13:22:37 -04:00
17 changed files with 673 additions and 33 deletions

View File

@ -1,4 +1,5 @@
use crate::models::{Album, Artist, Song};
use crate::components::dashboard_tile::DashboardTile;
use serde::{Serialize, Deserialize};
use time::Date;
@ -6,7 +7,7 @@ use time::Date;
/// Holds information about a song
///
/// Intended to be used in the front-end, as it includes artist and album objects, rather than just their ids.
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
pub struct SongData {
/// Song id
pub id: i32,
@ -62,3 +63,21 @@ impl TryInto<Song> for SongData {
})
}
}
impl DashboardTile for SongData {
fn image_path(&self) -> String {
self.image_path.clone()
}
fn title(&self) -> String {
self.title.clone()
}
fn link(&self) -> String {
format!("/song/{}", self.id)
}
fn description(&self) -> Option<String> {
Some(format!("Song • {}", Artist::display_list(&self.artists)))
}
}