Code formatting

This commit is contained in:
kdeng00
2025-04-26 18:30:58 -04:00
parent 8a017e346e
commit a8076ddcf4
2 changed files with 35 additions and 28 deletions
+6 -5
View File
@@ -226,7 +226,8 @@ pub mod endpoint {
pub async fn download_flac( pub async fn download_flac(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>) -> (StatusCode, axum::response::Response) { axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (StatusCode, axum::response::Response) {
println!("Id: {:?}", id); println!("Id: {:?}", id);
match song_queue::get_data(&pool, &id).await { match song_queue::get_data(&pool, &id).await {
@@ -240,14 +241,14 @@ pub mod endpoint {
); );
headers.insert( headers.insert(
axum::http::header::CONTENT_DISPOSITION, axum::http::header::CONTENT_DISPOSITION,
format!("attachment; filename=\"{}.flac\"", id).parse().unwrap(), format!("attachment; filename=\"{}.flac\"", id)
.parse()
.unwrap(),
); );
(StatusCode::OK, response) (StatusCode::OK, response)
} }
Err(_err) => { Err(_err) => (StatusCode::BAD_REQUEST, axum::response::Response::default()),
(StatusCode::BAD_REQUEST, axum::response::Response::default())
}
} }
} }
} }
+19 -13
View File
@@ -231,7 +231,9 @@ mod tests {
app.clone().oneshot(req).await app.clone().oneshot(req).await
} }
async fn fetch_queue_req(app: &axum::Router,) -> Result<axum::response::Response, std::convert::Infallible> { async fn fetch_queue_req(
app: &axum::Router,
) -> Result<axum::response::Response, std::convert::Infallible> {
let fetch_req = axum::http::Request::builder() let fetch_req = axum::http::Request::builder()
.method(axum::http::Method::GET) .method(axum::http::Method::GET)
.uri(crate::callers::endpoints::NEXTQUEUESONG) .uri(crate::callers::endpoints::NEXTQUEUESONG)
@@ -241,7 +243,10 @@ mod tests {
app.clone().oneshot(fetch_req).await app.clone().oneshot(fetch_req).await
} }
async fn fetch_queue_data_req(app: &axum::Router, id: &uuid::Uuid) -> Result<axum::response::Response, std::convert::Infallible> { async fn fetch_queue_data_req(
app: &axum::Router,
id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> {
let raw_uri = String::from(crate::callers::endpoints::QUEUESONGDATA); let raw_uri = String::from(crate::callers::endpoints::QUEUESONGDATA);
let end_index = raw_uri.len() - 4; let end_index = raw_uri.len() - 4;
let mut uri: String = (&raw_uri[..end_index]).to_string(); let mut uri: String = (&raw_uri[..end_index]).to_string();
@@ -256,18 +261,17 @@ mod tests {
app.clone().oneshot(req).await app.clone().oneshot(req).await
} }
pub async fn resp_to_bytes(response: axum::response::Response) -> Result<axum::body::Bytes, axum::Error> { pub async fn resp_to_bytes(
axum::body::to_bytes(response.into_body(), usize::MAX) response: axum::response::Response,
.await ) -> Result<axum::body::Bytes, axum::Error> {
axum::body::to_bytes(response.into_body(), usize::MAX).await
} }
pub async fn get_resp_data<Data>(response: axum::response::Response) -> Data pub async fn get_resp_data<Data>(response: axum::response::Response) -> Data
where where
Data: for<'a> serde::Deserialize<'a>, Data: for<'a> serde::Deserialize<'a>,
{ {
let body = resp_to_bytes(response) let body = resp_to_bytes(response).await.unwrap();
.await
.unwrap();
serde_json::from_slice(&body).unwrap() serde_json::from_slice(&body).unwrap()
} }
@@ -391,16 +395,18 @@ mod tests {
let id = resp.data[0].id; let id = resp.data[0].id;
match fetch_queue_data_req(&app, &id).await { match fetch_queue_data_req(&app, &id).await {
Ok(response) => { Ok(response) => match resp_to_bytes(response).await {
match resp_to_bytes(response).await {
Ok(bytes) => { Ok(bytes) => {
assert_eq!(false, bytes.is_empty(), "Queued data should not be empty"); assert_eq!(
false,
bytes.is_empty(),
"Queued data should not be empty"
);
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err); assert!(false, "Error: {:?}", err);
} }
} },
}
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err); assert!(false, "Error: {:?}", err);
} }