Code formatting

This commit is contained in:
kdeng00
2025-05-22 16:13:06 -04:00
parent ca85a5d46d
commit b93db64c20
2 changed files with 50 additions and 34 deletions
+20 -21
View File
@@ -118,25 +118,26 @@ mod song_queue {
pool: &sqlx::PgPool, pool: &sqlx::PgPool,
data: &Vec<u8>, data: &Vec<u8>,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<Vec<u8>, sqlx::Error> { ) -> Result<Vec<u8>, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
UPDATE "songQueue" SET data = $1 WHERE id = $2 RETURNING data; UPDATE "songQueue" SET data = $1 WHERE id = $2 RETURNING data;
"# "#,
) )
.bind(data) .bind(data)
.bind(id) .bind(id)
.fetch_one(pool) .fetch_one(pool)
.await .await
.map_err(|e| { .map_err(|e| {
eprintln!("Error inserting: {:?}", e); eprintln!("Error inserting: {:?}", e);
}); });
match result { match result {
Ok(row) => { Ok(row) => Ok(row
Ok(row.try_get("data").map_err(|_e| sqlx::Error::RowNotFound).unwrap()) .try_get("data")
} .map_err(|_e| sqlx::Error::RowNotFound)
Err(_) => Err(sqlx::Error::RowNotFound) .unwrap()),
Err(_) => Err(sqlx::Error::RowNotFound),
} }
} }
@@ -419,8 +420,10 @@ pub mod endpoint {
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>, axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
mut multipart: axum::extract::Multipart, mut multipart: axum::extract::Multipart,
) -> (axum::http::StatusCode, axum::Json<super::response::update_song_queue::Response>) { ) -> (
axum::http::StatusCode,
axum::Json<super::response::update_song_queue::Response>,
) {
let mut response = super::response::update_song_queue::Response::default(); let mut response = super::response::update_song_queue::Response::default();
if let Some(field) = multipart.next_field().await.unwrap() { if let Some(field) = multipart.next_field().await.unwrap() {
@@ -442,11 +445,7 @@ pub mod endpoint {
// file.write_all(&data).unwrap(); // file.write_all(&data).unwrap();
let raw_data: Vec<u8> = data.to_vec(); let raw_data: Vec<u8> = data.to_vec();
match song_queue::update( match song_queue::update(&pool, &raw_data, &id).await {
&pool,
&raw_data,
&id,
).await {
Ok(queued_data) => { Ok(queued_data) => {
response.data.push(queued_data); response.data.push(queued_data);
(axum::http::StatusCode::OK, axum::Json(response)) (axum::http::StatusCode::OK, axum::Json(response))
+30 -13
View File
@@ -83,7 +83,7 @@ pub mod init {
) )
.route( .route(
crate::callers::endpoints::QUEUESONGUPDATE, crate::callers::endpoints::QUEUESONGUPDATE,
patch(crate::callers::song::endpoint::update_song_queue) patch(crate::callers::song::endpoint::update_song_queue),
) )
.route( .route(
crate::callers::endpoints::QUEUEMETADATA, crate::callers::endpoints::QUEUEMETADATA,
@@ -1124,7 +1124,8 @@ mod tests {
// let new_file = String::from("tests/Machine_gun/new_file.flac"); // let new_file = String::from("tests/Machine_gun/new_file.flac");
let temp_file = tempfile::tempdir().expect("Could not create test directory"); let temp_file = tempfile::tempdir()
.expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap()); let test_dir = String::from(temp_file.path().to_str().unwrap());
let new_file = format!("{}/new_file.flac", test_dir); let new_file = format!("{}/new_file.flac", test_dir);
@@ -1138,28 +1139,44 @@ mod tests {
let content_type = form.content_type(); let content_type = form.content_type();
let body = MultipartBody::from(form); let body = MultipartBody::from(form);
let raw_uri = String::from(crate::callers::endpoints::QUEUESONGUPDATE); let raw_uri =
String::from(crate::callers::endpoints::QUEUESONGUPDATE);
let end_index = raw_uri.len() - 5; let end_index = raw_uri.len() - 5;
// let mut uri: String = (&raw_uri[..end_index]).to_string(); // let mut uri: String = (&raw_uri[..end_index]).to_string();
// uri += &id.to_string(); // uri += &id.to_string();
let uri = format!("{}/{}", (&raw_uri[..end_index]).to_string(), id.to_string()); let uri = format!(
"{}/{}",
(&raw_uri[..end_index]).to_string(),
id.to_string()
);
// app.clone().oneshot(req).await // app.clone().oneshot(req).await
match app.clone().oneshot( match app
axum::http::Request::builder() .clone()
.method(axum::http::Method::PATCH) .oneshot(
.uri(uri) axum::http::Request::builder()
.header(axum::http::header::CONTENT_TYPE, content_type) .method(axum::http::Method::PATCH)
.body(axum::body::Body::from_stream(body)) .uri(uri)
.unwrap() .header(
).await { axum::http::header::CONTENT_TYPE,
content_type,
)
.body(axum::body::Body::from_stream(body))
.unwrap(),
)
.await
{
Ok(response) => { Ok(response) => {
let resp = get_resp_data::< let resp = get_resp_data::<
crate::callers::song::response::update_song_queue::Response, crate::callers::song::response::update_song_queue::Response,
>(response) >(response)
.await; .await;
assert_eq!(false, resp.data.is_empty(), "Should not be empty"); assert_eq!(
false,
resp.data.is_empty(),
"Should not be empty"
);
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err); assert!(false, "Error: {:?}", err);