Code formatting
This commit is contained in:
+17
-14
@@ -59,24 +59,24 @@ mod db {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update(pool: &sqlx::PgPool, coverart_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,) -> Result<i32, sqlx::Error> {
|
||||
pub async fn update(
|
||||
pool: &sqlx::PgPool,
|
||||
coverart_id: &uuid::Uuid,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<i32, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
UPDATE "coverartQueue" SET song_queue_id = $1 WHERE id = $2;
|
||||
"#
|
||||
)
|
||||
.bind(song_queue_id)
|
||||
.bind(coverart_id)
|
||||
.execute(pool)
|
||||
.await;
|
||||
"#,
|
||||
)
|
||||
.bind(song_queue_id)
|
||||
.bind(coverart_id)
|
||||
.execute(pool)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(_) => {
|
||||
Ok(0)
|
||||
}
|
||||
Err(_err) => {
|
||||
Err(sqlx::Error::RowNotFound)
|
||||
}
|
||||
Ok(_) => Ok(0),
|
||||
Err(_err) => Err(sqlx::Error::RowNotFound),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,10 @@ pub mod endpoint {
|
||||
pub async fn link(
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
axum::Json(payload): axum::Json<super::request::link::Request>,
|
||||
) -> (axum::http::StatusCode, axum::Json<super::response::link::Response>,) {
|
||||
) -> (
|
||||
axum::http::StatusCode,
|
||||
axum::Json<super::response::link::Response>,
|
||||
) {
|
||||
let mut response = super::response::link::Response::default();
|
||||
let coverart_id = payload.coverart_id;
|
||||
let song_queue_id = payload.song_queue_id;
|
||||
|
||||
+34
-31
@@ -92,7 +92,7 @@ pub mod init {
|
||||
.route(
|
||||
crate::callers::endpoints::QUEUECOVERARTLINK,
|
||||
patch(crate::callers::coverart::endpoint::link),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn app() -> axum::Router {
|
||||
@@ -275,7 +275,7 @@ mod tests {
|
||||
|
||||
async fn upload_coverart_queue_req(
|
||||
app: &axum::Router,
|
||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||
let mut form = MultipartForm::default();
|
||||
let _ = form.add_file("jpg", "tests/Machine_gun/160809_machinegun.jpg");
|
||||
|
||||
@@ -284,19 +284,14 @@ mod tests {
|
||||
let body = MultipartBody::from(form);
|
||||
|
||||
let req = axum::http::Request::builder()
|
||||
.method(axum::http::Method::POST)
|
||||
.uri(crate::callers::endpoints::QUEUECOVERART)
|
||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
||||
.body(axum::body::Body::from_stream(body))
|
||||
.unwrap();
|
||||
.method(axum::http::Method::POST)
|
||||
.uri(crate::callers::endpoints::QUEUECOVERART)
|
||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
||||
.body(axum::body::Body::from_stream(body))
|
||||
.unwrap();
|
||||
|
||||
// Send request
|
||||
app
|
||||
.clone()
|
||||
.oneshot(
|
||||
req
|
||||
)
|
||||
.await
|
||||
app.clone().oneshot(req).await
|
||||
}
|
||||
|
||||
pub async fn resp_to_bytes(
|
||||
@@ -646,8 +641,7 @@ mod tests {
|
||||
let app = init::app(pool).await;
|
||||
|
||||
// Send request
|
||||
match upload_coverart_queue_req(&app).await
|
||||
{
|
||||
match upload_coverart_queue_req(&app).await {
|
||||
Ok(response) => {
|
||||
let resp =
|
||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
||||
@@ -684,18 +678,18 @@ mod tests {
|
||||
|
||||
match song_queue_req(&app).await {
|
||||
Ok(response) => {
|
||||
let resp =
|
||||
let resp =
|
||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||
let song_queue_id = resp.data[0];
|
||||
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
||||
|
||||
// Send request
|
||||
match upload_coverart_queue_req(&app).await
|
||||
{
|
||||
match upload_coverart_queue_req(&app).await {
|
||||
Ok(response) => {
|
||||
let resp =
|
||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
||||
get_resp_data::<crate::callers::coverart::response::Response>(response)
|
||||
.await;
|
||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||
let coverart_id = resp.data[0];
|
||||
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
||||
@@ -706,23 +700,33 @@ mod tests {
|
||||
"coverart_id" : coverart_id,
|
||||
});
|
||||
|
||||
match app.clone().oneshot(
|
||||
axum::http::Request::builder()
|
||||
.method(axum::http::Method::PATCH)
|
||||
.uri(crate::callers::endpoints::QUEUECOVERARTLINK)
|
||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||
.body(axum::body::Body::from(payload.to_string()))
|
||||
.unwrap(),
|
||||
).await {
|
||||
match app
|
||||
.clone()
|
||||
.oneshot(
|
||||
axum::http::Request::builder()
|
||||
.method(axum::http::Method::PATCH)
|
||||
.uri(crate::callers::endpoints::QUEUECOVERARTLINK)
|
||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||
.body(axum::body::Body::from(payload.to_string()))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
let resp =
|
||||
get_resp_data::<crate::callers::coverart::response::link::Response>(response).await;
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::link::Response,
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||
let resp_coverart_id = resp.data[0].coverart_id;
|
||||
let resp_song_queue_id = resp.data[0].song_queue_id;
|
||||
|
||||
assert_eq!(false, resp_coverart_id.is_nil(), "Should not be empty");
|
||||
assert_eq!(false, resp_song_queue_id.is_nil(), "Should not be empty");
|
||||
assert_eq!(
|
||||
false,
|
||||
resp_song_queue_id.is_nil(),
|
||||
"Should not be empty"
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
@@ -739,7 +743,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user