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