Code refactor
This commit is contained in:
+34
-24
@@ -82,9 +82,7 @@ mod song_queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_most_recent_and_update(
|
pub async fn get_most_recent_and_update(pool: &sqlx::PgPool) -> Result<SongQueue, sqlx::Error> {
|
||||||
pool: &sqlx::PgPool,
|
|
||||||
) -> Result<SongQueue, sqlx::Error> {
|
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE "songQueue"
|
UPDATE "songQueue"
|
||||||
@@ -98,27 +96,35 @@ mod song_queue {
|
|||||||
)
|
)
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.bind(status::PROCESSING)
|
.bind(status::PROCESSING)
|
||||||
.bind(status::PENDING)
|
.bind(status::PENDING)
|
||||||
.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(SongQueue {
|
||||||
Ok(SongQueue{
|
id: row
|
||||||
id: row.try_get("id").map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
filename: row.try_get("filename").map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
status: row.try_get("status").map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
data: row.try_get("data").map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
filename: row
|
||||||
})
|
.try_get("filename")
|
||||||
}
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
Err(err) => {
|
.unwrap(),
|
||||||
Err(sqlx::Error::RowNotFound)
|
status: row
|
||||||
}
|
.try_get("status")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
|
data: row
|
||||||
|
.try_get("data")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
|
}),
|
||||||
|
Err(err) => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,8 +182,12 @@ pub mod endpoint {
|
|||||||
(StatusCode::OK, Json(response))
|
(StatusCode::OK, Json(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_queue_song(axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
pub async fn fetch_queue_song(
|
||||||
) -> (StatusCode, Json<super::response::fetch_queue_song::Response>) {
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
) -> (
|
||||||
|
StatusCode,
|
||||||
|
Json<super::response::fetch_queue_song::Response>,
|
||||||
|
) {
|
||||||
let mut response = super::response::fetch_queue_song::Response::default();
|
let mut response = super::response::fetch_queue_song::Response::default();
|
||||||
|
|
||||||
match song_queue::get_most_recent_and_update(&pool).await {
|
match song_queue::get_most_recent_and_update(&pool).await {
|
||||||
|
|||||||
+2
-1
@@ -69,7 +69,8 @@ pub mod init {
|
|||||||
crate::callers::endpoints::QUEUESONG,
|
crate::callers::endpoints::QUEUESONG,
|
||||||
post(crate::callers::song::endpoint::queue_song),
|
post(crate::callers::song::endpoint::queue_song),
|
||||||
)
|
)
|
||||||
.route(crate::callers::endpoints::NEXTQUEUESONG,
|
.route(
|
||||||
|
crate::callers::endpoints::NEXTQUEUESONG,
|
||||||
get(crate::callers::song::endpoint::fetch_queue_song),
|
get(crate::callers::song::endpoint::fetch_queue_song),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
Reference in New Issue
Block a user