Compare commits

..

1 Commits

Author SHA1 Message Date
abfec8d287 tsk-57: Adding utoipia crate for documentation
All checks were successful
Release Tagging / release (pull_request) Successful in 39s
Rust Build / Test Suite (pull_request) Successful in 57s
Rust Build / Check (pull_request) Successful in 59s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 36s
Rust Build / build (pull_request) Successful in 51s
2025-08-19 18:08:10 -04:00
8 changed files with 58 additions and 101 deletions

3
Cargo.lock generated
View File

@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
[[package]]
name = "icarus_models"
version = "0.6.0"
version = "0.5.5"
dependencies = [
"josekit",
"rand",
@@ -550,7 +550,6 @@ dependencies = [
"proc-macro2",
"quote",
"syn",
"uuid",
]
[[package]]

View File

@@ -1,6 +1,6 @@
[package]
name = "icarus_models"
version = "0.6.0"
version = "0.5.5"
edition = "2024"
rust-version = "1.88"
description = "models used for the icarus project"
@@ -13,7 +13,7 @@ rand = { version = "0.9.1" }
time = { version = "0.3.41", features = ["formatting", "macros", "parsing", "serde"] }
uuid = { version = "1.17.0", features = ["v4", "serde"] }
josekit = { version = "0.10.3" }
utoipa = { version = "5.4.0", features = ["uuid", "time"] }
utoipa = { version = "5.4.0" }
[dev-dependencies]
tempfile = { version = "3.20.0" }

View File

@@ -2,7 +2,7 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AccessLevel {
pub id: uuid::Uuid,
pub level: String,

View File

@@ -2,7 +2,7 @@ use std::io::Read;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CoverArt {
pub id: uuid::Uuid,
pub title: String,
@@ -37,9 +37,6 @@ impl CoverArt {
Err(err) => Err(err),
}
}
// TODO: Add method to save to filesystem
// TODO: Add method to remove from filesystem
}
#[cfg(test)]

View File

@@ -2,7 +2,7 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LoginResult {
pub id: uuid::Uuid,
pub username: String,

View File

@@ -1,13 +1,13 @@
use std::io::{Read, Write};
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::io::Read;
use crate::constants;
use crate::init;
use crate::types;
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
use rand::Rng;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Song {
#[serde(skip_serializing_if = "init::is_uuid_nil")]
#[serde(alias = "id")]
@@ -90,7 +90,6 @@ 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();
@@ -110,7 +109,6 @@ 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;
@@ -152,53 +150,4 @@ impl Song {
filename
}
/// Saves the song to the filesystem using the song's data
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
}
/// I/O operations for songs
pub mod io {
/// Copies a song using the source song's data
pub fn copy_song(
song_source: &super::Song,
song_target: &mut super::Song,
) -> Result<(), std::io::Error> {
match song_target.song_path() {
Ok(songpath) => {
let p = std::path::Path::new(&songpath);
if p.exists() {
Err(std::io::Error::other(
"Cannot copy song over to one that already exists",
))
} else {
if song_target.data.is_empty() {
song_target.data = song_source.data.clone();
} else {
song_target.data.clear();
song_target.data = song_source.data.clone();
}
match song_target.save_to_filesystem() {
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
}
Err(err) => Err(err),
}
}
}

View File

@@ -4,7 +4,7 @@ use crate::init;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct User {
#[serde(skip_serializing_if = "init::is_uuid_nil")]
pub id: uuid::Uuid,

View File

@@ -30,12 +30,16 @@ mod utils {
#[cfg(test)]
mod song_tests {
use std::fs::File;
use std::io::Write;
use tempfile::tempdir;
use crate::utils;
use icarus_models::song;
use icarus_models::types;
use crate::utils;
#[test]
fn test_song_to_data() {
println!("Test");
@@ -99,42 +103,50 @@ mod song_tests {
song.directory = utils::get_tests_directory();
song.filename = String::from("track01.flac");
let mut song_cpy = song.clone();
let temp_dir = tempdir().expect("Failed to create temp dir");
song_cpy.directory = match temp_dir.path().to_str() {
Some(s) => String::from(s),
None => String::new(),
};
match song.song_path() {
Ok(songpath) => match utils::extract_data_from_file(&songpath) {
Ok(buffer) => {
let mut song_cpy = song.clone();
let temp_dir = tempdir().expect("Failed to create temp dir");
song_cpy.directory = match temp_dir.path().to_str() {
Some(s) => String::from(s),
None => String::new(),
};
assert_eq!(song.directory.is_empty(), false);
song_cpy.filename = song.generate_filename(types::MusicTypes::FlacExtension, true);
println!("Directory: {:?}", song_cpy.directory);
println!("File to be created: {:?}", song_cpy.filename);
assert_eq!(song.directory.is_empty(), false);
song_cpy.filename =
song.generate_filename(types::MusicTypes::FlacExtension, true);
println!("Directory: {:?}", song_cpy.directory);
println!("File to be created: {:?}", song_cpy.filename);
match song::copy_song(&song, &mut song_cpy) {
Ok(_) => {}
let path = match song_cpy.song_path() {
Ok(s_path) => s_path,
Err(err) => {
assert!(false, "Error: {:?}", err);
String::new()
}
};
match File::create(path) {
Ok(mut file_cpy) => match file_cpy.write_all(&buffer) {
Ok(success) => {
println!("Success: {:?}", success);
}
Err(err) => {
assert!(false, "Error saving file: {:?}", err);
}
},
Err(err) => {
assert!(false, "Error: {:?}", err);
}
};
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
},
Err(err) => {
assert!(false, "Error copying song: Error: {err:?}")
}
}
}
#[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");
let mut copied_song = song::Song {
directory: utils::get_tests_directory(),
filename: String::from("track02-coppied.flac"),
..Default::default()
};
match song::copy_song(&song, &mut copied_song) {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {err:?}")
assert!(false, "Error extracting song data: {:?}", err);
}
}
}