Compare commits

..

7 Commits

Author SHA1 Message Date
9436c9033a Added todo
All checks were successful
Release Tagging / release (pull_request) Successful in 44s
Rust Build / Test Suite (pull_request) Successful in 49s
Rust Build / Check (pull_request) Successful in 57s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 47s
Rust Build / build (pull_request) Successful in 59s
2025-10-11 14:23:23 -04:00
85d8f839f1 Code formatting
All checks were successful
Rust Build / Test Suite (pull_request) Successful in 1m38s
Rust Build / Rustfmt (pull_request) Successful in 32s
Release Tagging / release (pull_request) Successful in 2m17s
Rust Build / Check (pull_request) Successful in 2m30s
Rust Build / Clippy (pull_request) Successful in 57s
Rust Build / build (pull_request) Successful in 1m1s
2025-10-11 14:19:45 -04:00
16f633d563 Added test 2025-10-11 14:19:30 -04:00
0b53eb8208 Added more todos 2025-10-11 14:19:21 -04:00
73c8fd2634 Tweaked some changes 2025-10-11 14:17:32 -04:00
fa8643e73a Added function to save song to the filesystem 2025-10-11 14:08:20 -04:00
2d6b550ae6 tsk-57: Adding derive Schema to models (#58)
All checks were successful
Rust Build / Check (push) Successful in 31s
Rust Build / Test Suite (push) Successful in 1m0s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 37s
Rust Build / build (push) Successful in 46s
Closes #57

Reviewed-on: #58
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-24 23:42:04 +00:00
3 changed files with 56 additions and 1 deletions

View File

@@ -37,6 +37,9 @@ impl CoverArt {
Err(err) => Err(err),
}
}
// TODO: Add method to save to filesystem
// TODO: Add method to remove from filesystem
}
#[cfg(test)]

View File

@@ -1,4 +1,4 @@
use std::io::Read;
use std::io::{Read, Write};
use crate::constants;
use crate::init;
@@ -90,6 +90,7 @@ impl Song {
}
}
// TODO: Make this available as a function
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
let path_result = self.song_path();
@@ -109,6 +110,7 @@ impl Song {
}
}
// TODO: Make this available as a function
pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String {
let mut filename: String = String::new();
let filename_len = 10;
@@ -150,4 +152,21 @@ impl Song {
filename
}
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
match self.song_path() {
Ok(song_path) => match std::fs::File::create(&song_path) {
Ok(mut file) => match file.write_all(&self.data) {
Ok(_res) => Ok(()),
Err(err) => Err(err),
},
Err(err) => Err(err),
},
Err(err) => Err(err),
}
}
// TODO: Add function to remove file from the filesystem
}
// TODO: Add function to copy song

View File

@@ -150,6 +150,39 @@ mod song_tests {
}
}
}
#[test]
fn test_save_song_to_filesystem() {
let mut song = song::Song::default();
song.directory = utils::get_tests_directory();
song.filename = String::from("track02.flac");
match song.song_path() {
Ok(song_path) => match utils::extract_data_from_file(&song_path) {
Ok(data) => {
let copied_song = song::Song {
directory: utils::get_tests_directory(),
filename: String::from("track02-coppied.flac"),
data: data,
..Default::default()
};
match copied_song.save_to_filesystem() {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {err:?}")
}
}
}
Err(err) => {
assert!(false, "Error: {err:?}")
}
},
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
}
#[cfg(test)]