diff --git a/nghe-api/src/id3/song/full.rs b/nghe-api/src/id3/song/full.rs index 05a42e6a..2711e7af 100644 --- a/nghe-api/src/id3/song/full.rs +++ b/nghe-api/src/id3/song/full.rs @@ -1,14 +1,11 @@ use nghe_proc_macro::api_derive; -use uuid::Uuid; -use super::Song; +use super::Short; use crate::id3::genre; #[api_derive] pub struct Full { #[serde(flatten)] - pub song: Song, - pub album: String, - pub album_id: Uuid, + pub short: Short, pub genres: genre::Genres, } diff --git a/nghe-backend/src/orm/id3/song/full.rs b/nghe-backend/src/orm/id3/song/full.rs index 53956c4b..bdadfdd9 100644 --- a/nghe-backend/src/orm/id3/song/full.rs +++ b/nghe-backend/src/orm/id3/song/full.rs @@ -1,12 +1,9 @@ -use diesel::dsl::sql; -use diesel::expression::SqlLiteral; use diesel::prelude::*; -use diesel::sql_types; use nghe_api::id3; use o2o::o2o; use uuid::Uuid; -use super::Song; +use super::short::Short; use crate::orm::id3::genre; use crate::Error; @@ -15,13 +12,7 @@ use crate::Error; pub struct Full { #[into(~.try_into()?)] #[diesel(embed)] - pub song: Song, - #[diesel(select_expression = sql("any_value(albums.name) album_name"))] - #[diesel(select_expression_type = SqlLiteral)] - pub album: String, - #[diesel(select_expression = sql("any_value(albums.id) album_id"))] - #[diesel(select_expression_type = SqlLiteral)] - pub album_id: Uuid, + pub short: Short, #[into(~.into())] #[diesel(embed)] pub genres: genre::Genres, @@ -103,9 +94,9 @@ mod test { if allow { let database_song = database_song.unwrap(); - let database_artists: Vec = database_song.song.artists.into(); - assert_eq!(database_song.album, album.name); - assert_eq!(database_song.album_id, album_id); + let database_artists: Vec = database_song.short.song.artists.into(); + assert_eq!(database_song.short.album, album.name); + assert_eq!(database_song.short.album_id, album_id); assert_eq!(database_artists, artists); assert_eq!(database_song.genres.value.len(), n_genre); } else { diff --git a/nghe-backend/src/route/browsing/get_song.rs b/nghe-backend/src/route/browsing/get_song.rs index 09529090..859d980d 100644 --- a/nghe-backend/src/route/browsing/get_song.rs +++ b/nghe-backend/src/route/browsing/get_song.rs @@ -60,11 +60,11 @@ mod test { .unwrap() .song; - assert_eq!(database_song.album, album.name); - assert_eq!(database_song.album_id, album_id); + assert_eq!(database_song.short.album, album.name); + assert_eq!(database_song.short.album_id, album_id); let database_artists: Vec<_> = - database_song.song.artists.into_iter().map(|artist| artist.name).collect(); + database_song.short.song.artists.into_iter().map(|artist| artist.name).collect(); assert_eq!(database_artists, artists); let genres = database_song.genres.value;