Code formatting
This commit is contained in:
+28
-18
@@ -111,7 +111,7 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::coverart::CoverArt>
|
pub data: Vec<icarus_models::coverart::CoverArt>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,7 +337,10 @@ pub mod cov_db {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_coverart(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
pub async fn get_coverart(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, title, path, song_id FROM "coverart" WHERE id = $1;
|
SELECT id, title, path, song_id FROM "coverart" WHERE id = $1;
|
||||||
@@ -360,9 +363,15 @@ pub mod cov_db {
|
|||||||
.try_get("title")
|
.try_get("title")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
path: row.try_get("path").map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
path: row
|
||||||
|
.try_get("path")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
data: Vec::new(),
|
data: Vec::new(),
|
||||||
song_id: row.try_get("song_id").map_err(|_e| sqlx::Error::RowNotFound).unwrap()
|
song_id: row
|
||||||
|
.try_get("song_id")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
}),
|
}),
|
||||||
Err(_) => Err(sqlx::Error::RowNotFound),
|
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
}
|
||||||
@@ -609,24 +618,25 @@ pub mod endpoint {
|
|||||||
|
|
||||||
pub async fn get_coverart(
|
pub async fn get_coverart(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::extract::Query(params): axum::extract::Query<super::request::get_coverart::Params>
|
axum::extract::Query(params): axum::extract::Query<super::request::get_coverart::Params>,
|
||||||
) -> (axum::http::StatusCode, axum::Json<super::response::get_coverart::Response>) {
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::get_coverart::Response>,
|
||||||
|
) {
|
||||||
let mut response = super::response::get_coverart::Response::default();
|
let mut response = super::response::get_coverart::Response::default();
|
||||||
|
|
||||||
match params.id {
|
match params.id {
|
||||||
Some(id) => {
|
Some(id) => match super::cov_db::get_coverart(&pool, &id).await {
|
||||||
match super::cov_db::get_coverart(&pool, &id).await {
|
Ok(coverart) => {
|
||||||
Ok(coverart) => {
|
response.data.push(coverart);
|
||||||
response.data.push(coverart);
|
response.message = String::from(super::super::response::SUCCESSFUL);
|
||||||
response.message = String::from(super::super::response::SUCCESSFUL);
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
},
|
||||||
None => {
|
None => {
|
||||||
response.message = String::from("Invalid parameters");
|
response.message = String::from("Invalid parameters");
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
|||||||
+3
-3
@@ -121,8 +121,8 @@ pub mod init {
|
|||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::GETCOVERART,
|
crate::callers::endpoints::GETCOVERART,
|
||||||
get(crate::callers::coverart::endpoint::get_coverart)
|
get(crate::callers::coverart::endpoint::get_coverart),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn app() -> axum::Router {
|
pub async fn app() -> axum::Router {
|
||||||
@@ -1902,7 +1902,7 @@ mod tests {
|
|||||||
let app = super::init::app(pool).await;
|
let app = super::init::app(pool).await;
|
||||||
|
|
||||||
let mut id = uuid::Uuid::nil();
|
let mut id = uuid::Uuid::nil();
|
||||||
|
|
||||||
match uuid::Uuid::parse_str("996122cd-5ae9-4013-9934-60768d3006ed") {
|
match uuid::Uuid::parse_str("996122cd-5ae9-4013-9934-60768d3006ed") {
|
||||||
Ok(val) => {
|
Ok(val) => {
|
||||||
id = val;
|
id = val;
|
||||||
|
|||||||
Reference in New Issue
Block a user