Code refactoring

This commit is contained in:
kdeng00
2025-10-11 19:41:18 -04:00
parent 6a73d1c4db
commit 0b636d5557
+27 -1
View File
@@ -1229,8 +1229,33 @@ pub mod endpoint {
} }
} }
let save_path = dir.join(&song.filename); match song.save_to_filesystem() {
Ok(_) => {
match super::song_db::insert(&pool, &song).await {
Ok((date_created, id)) => {
song.id = id;
song.date_created = date_created;
response.message = String::from("Successful");
response.data.push(song);
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
response.message =
format!("{:?} song {:?}", err.to_string(), song);
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
}
Err(err) => {
response.message = err.to_string();
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
}
}
// let save_path = dir.join(&song.filename);
/*
match std::fs::File::create(&save_path) { match std::fs::File::create(&save_path) {
Ok(mut file) => { Ok(mut file) => {
file.write_all(&song.data).unwrap(); file.write_all(&song.data).unwrap();
@@ -1269,6 +1294,7 @@ pub mod endpoint {
) )
} }
} }
*/
} }
Err(err) => { Err(err) => {
response.message = err.to_string(); response.message = err.to_string();