icarus_models related changes

This commit is contained in:
kdeng00
2025-10-19 19:44:30 -04:00
parent 507f02044c
commit af1af57a7e
2 changed files with 51 additions and 29 deletions
+24 -12
View File
@@ -82,10 +82,11 @@ pub mod request {
audio_type: self.audio_type.clone(),
user_id: self.user_id,
// TODO: Change the type of this in icarus_models lib
date_created: String::new(),
filename: String::new(),
data: Vec::new(),
directory: String::new(),
// date_created: self.date_created,
// filename: String::new(),
// data: Vec::new(),
// directory: String::new(),
..Default::default()
}
}
}
@@ -224,7 +225,7 @@ pub mod song_db {
pub async fn insert(
pool: &sqlx::PgPool,
song: &icarus_models::song::Song,
) -> Result<(String, uuid::Uuid), sqlx::Error> {
) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> {
let result = sqlx::query(
r#"
INSERT INTO "song" (title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, filename, directory, user_id)
@@ -262,7 +263,7 @@ pub mod song_db {
.try_get("date_created")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap();
let date_created = date_created_time.to_string();
let date_created = date_created_time;
Ok((date_created, id))
}
@@ -354,7 +355,7 @@ pub mod song_db {
.try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: date_created_time.to_string(),
date_created: Some(date_created_time),
user_id: row
.try_get("user_id")
.map_err(|_e| sqlx::Error::RowNotFound)
@@ -451,7 +452,7 @@ pub mod song_db {
.try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: date_created_time.to_string(),
date_created: Some(date_created_time),
user_id: row
.try_get("user_id")
.map_err(|_e| sqlx::Error::RowNotFound)
@@ -555,7 +556,7 @@ pub mod song_db {
.try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: date_created_time.to_string(),
date_created: Some(date_created_time),
user_id: row
.try_get("user_id")
.map_err(|_e| sqlx::Error::RowNotFound)
@@ -1221,7 +1222,7 @@ pub mod endpoint {
Ok(_) => match super::song_db::insert(&pool, &song).await {
Ok((date_created, id)) => {
song.id = id;
song.date_created = date_created;
song.date_created = Some(date_created);
response.message = String::from("Successful");
response.data.push(song);
@@ -1495,7 +1496,18 @@ pub mod endpoint {
.await
{
Ok(coverart) => {
let coverart_path = std::path::Path::new(&coverart.path);
// let coverart_path = std::path::Path::new(&coverart.path);
let coverart_path_str = match coverart.get_path() {
Ok(path) => {
path
}
Err(err) => {
response.message = err.to_string();
return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response));
}
};
let coverart_path = std::path::Path::new(&coverart_path_str);
if coverart_path.exists() {
match song.song_path() {
Ok(song_path) => {
@@ -1510,7 +1522,7 @@ pub mod endpoint {
Ok(deleted_coverart) => {
match std::fs::remove_file(song_path) {
Ok(_) => match std::fs::remove_file(
&coverart.path,
&coverart_path
) {
Ok(_) => {
response.message = String::from(super::super::response::SUCCESSFUL);