From f772cc8f197d21dfa814f4986c4b4515c8d98505 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 3 Apr 2025 22:01:45 -0400 Subject: [PATCH 1/4] Added function to make coverart init easier --- src/coverart.rs | 26 ++++++++++++++++++++++++++ tests/tests.rs | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/coverart.rs b/src/coverart.rs index ebbf013..8f55f24 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -10,6 +10,32 @@ pub struct CoverArt { pub data: Vec, } +pub mod init { + use crate::coverart::CoverArt; + + pub fn init_coverart_only_path(path: &String) -> CoverArt { + CoverArt { + id: uuid::Uuid::new_v4(), + title: String::new(), + path: path.clone(), + data: Vec::new(), + } + } +} + +#[cfg(test)] +mod tests { + use crate::coverart; + + #[test] + fn test_cover_art_image() { + let path: String = String::from("somepath"); + let coverart = coverart::init::init_coverart_only_path(&path); + + assert_eq!(path, coverart.path); + } +} + impl CoverArt { pub fn to_data(&self) -> Result, std::io::Error> { let path: &String = &self.path; diff --git a/tests/tests.rs b/tests/tests.rs index 7df899b..f281ea7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -28,6 +28,7 @@ mod utils { } } +#[cfg(test)] mod song_tests { use std::fs::File; use std::io::Write; @@ -151,6 +152,7 @@ mod song_tests { } } +#[cfg(test)] mod album_tests { use crate::utils; -- 2.43.0 From caae91dad5893b65486ad8556b871b6dad4b7190 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 3 Apr 2025 22:05:47 -0400 Subject: [PATCH 2/4] Clippy fixes --- src/coverart.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coverart.rs b/src/coverart.rs index 8f55f24..09be846 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -13,7 +13,7 @@ pub struct CoverArt { pub mod init { use crate::coverart::CoverArt; - pub fn init_coverart_only_path(path: &String) -> CoverArt { + pub fn init_coverart_only_path(path: String) -> CoverArt { CoverArt { id: uuid::Uuid::new_v4(), title: String::new(), -- 2.43.0 From 3858a10a23dd0ddbda468996d9c2c2d012fa31e7 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 3 Apr 2025 22:11:59 -0400 Subject: [PATCH 3/4] More changes --- src/access_level.rs | 4 ++-- src/coverart.rs | 2 +- src/login_result.rs | 2 +- src/song.rs | 27 ++++++++++----------------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/access_level.rs b/src/access_level.rs index a51dcef..3c828e1 100644 --- a/src/access_level.rs +++ b/src/access_level.rs @@ -12,7 +12,7 @@ pub struct AccessLevel { impl Default for AccessLevel { fn default() -> Self { AccessLevel { - id: uuid::Uuid::new_v4(), + id: uuid::Uuid::nil(), level: String::new(), song_id: uuid::Uuid::new_v4(), } @@ -21,7 +21,7 @@ impl Default for AccessLevel { pub fn default_level() -> AccessLevel { AccessLevel { - id: uuid::Uuid::new_v4(), + id: uuid::Uuid::nil(), level: String::from("Public"), song_id: uuid::Uuid::new_v4(), } diff --git a/src/coverart.rs b/src/coverart.rs index 09be846..1af0ae7 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -15,7 +15,7 @@ pub mod init { pub fn init_coverart_only_path(path: String) -> CoverArt { CoverArt { - id: uuid::Uuid::new_v4(), + id: uuid::Uuid::nil(), title: String::new(), path: path.clone(), data: Vec::new(), diff --git a/src/login_result.rs b/src/login_result.rs index c4b6740..29d60d9 100644 --- a/src/login_result.rs +++ b/src/login_result.rs @@ -15,7 +15,7 @@ pub struct LoginResult { impl Default for LoginResult { fn default() -> Self { LoginResult { - id: uuid::Uuid::new_v4(), + id: uuid::Uuid::nil(), username: String::new(), token: String::new(), token_type: String::new(), diff --git a/src/song.rs b/src/song.rs index bf277ff..5ed3440 100644 --- a/src/song.rs +++ b/src/song.rs @@ -227,9 +227,9 @@ mod embedded { // The song's duration is a floating point in seconds #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Song { - #[serde(skip_serializing_if = "is_embed_zero")] + #[serde(skip_serializing_if = "init::is_uuid_nil")] #[serde(alias = "id")] - pub id: i32, + pub id: uuid::Uuid, #[serde(skip_serializing_if = "String::is_empty")] pub title: String, #[serde(skip_serializing_if = "String::is_empty")] @@ -240,17 +240,17 @@ mod embedded { pub album_artist: String, #[serde(skip_serializing_if = "String::is_empty")] pub genre: String, - #[serde(skip_serializing_if = "is_embed_zero")] + #[serde(skip_serializing_if = "init::is_embed_zero")] pub year: i32, - #[serde(skip_serializing_if = "is_embed_dur_not_set")] + #[serde(skip_serializing_if = "init::is_embed_dur_not_set")] pub duration: f64, - #[serde(skip_serializing_if = "is_embed_zero")] + #[serde(skip_serializing_if = "init::is_embed_zero")] pub track: i32, - #[serde(skip_serializing_if = "is_embed_zero")] + #[serde(skip_serializing_if = "init::is_embed_zero")] pub disc: i32, - #[serde(skip_serializing_if = "is_embed_zero")] + #[serde(skip_serializing_if = "init::is_embed_zero")] pub disc_count: i32, - #[serde(skip_serializing_if = "is_embed_zero")] + #[serde(skip_serializing_if = "init::is_embed_zero")] pub track_count: i32, #[serde(skip_serializing_if = "String::is_empty")] pub audio_type: String, @@ -258,7 +258,7 @@ mod embedded { pub date_created: String, #[serde(skip_serializing_if = "String::is_empty")] pub filename: String, - #[serde(skip_serializing_if = "is_embed_zero")] + #[serde(skip_serializing_if = "init::is_embed_zero")] pub user_id: i32, #[serde(skip)] pub data: Vec, @@ -274,18 +274,11 @@ mod embedded { // pub coverart_id: i32, } - fn is_embed_zero(num: &i32) -> bool { - *num == 0 - } - - fn is_embed_dur_not_set(num: &f64) -> bool { - *num == 0.0 - } impl Default for Song { fn default() -> Self { Song { - id: 0, + id: uuid::Uuid::nil(), title: String::new(), artist: String::new(), album: String::new(), -- 2.43.0 From 12134e7cc4c350fda374a2fbd1611a4c4aa606ff Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 3 Apr 2025 22:17:43 -0400 Subject: [PATCH 4/4] Fix --- src/coverart.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/coverart.rs b/src/coverart.rs index 1af0ae7..810d4e1 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -23,19 +23,6 @@ pub mod init { } } -#[cfg(test)] -mod tests { - use crate::coverart; - - #[test] - fn test_cover_art_image() { - let path: String = String::from("somepath"); - let coverart = coverart::init::init_coverart_only_path(&path); - - assert_eq!(path, coverart.path); - } -} - impl CoverArt { pub fn to_data(&self) -> Result, std::io::Error> { let path: &String = &self.path; @@ -47,3 +34,16 @@ impl CoverArt { } } } + +#[cfg(test)] +mod tests { + use crate::coverart; + + #[test] + fn test_cover_art_image() { + let path: String = String::from("somepath"); + let coverart = coverart::init::init_coverart_only_path(path.clone()); + + assert_eq!(path, coverart.path); + } +} -- 2.43.0