Delete song endpoint (#167)

* Added initial code for delete song endpoint

* Saving changes

* More changes

* Made delete song endpoint available

* Response change

* Added test function

* Changes to code

Fixing errors

* How did I miss this?

* Got the test working

* Code cleanup and formatting

* Version bump

* Code changes

* Workflow change
This commit was merged in pull request #167.
This commit is contained in:
KD
2025-07-29 21:34:16 -04:00
committed by GitHub
parent c7230d3b32
commit a0c6ae65a3
7 changed files with 359 additions and 5 deletions
+63 -2
View File
@@ -44,7 +44,7 @@ async fn main() {
}
pub mod init {
use axum::routing::{get, patch, post};
use axum::routing::{delete, get, patch, post};
use std::time::Duration;
use tower_http::timeout::TimeoutLayer;
@@ -135,6 +135,10 @@ pub mod init {
crate::callers::endpoints::DOWNLOADSONG,
get(crate::callers::song::endpoint::download_song),
)
.route(
crate::callers::endpoints::DELETESONG,
delete(crate::callers::song::endpoint::delete_song),
)
}
pub async fn app() -> axum::Router {
@@ -1835,7 +1839,7 @@ mod tests {
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
}
pub mod after_song_queue {
pub mod zzz_after_song_queue {
use futures::StreamExt;
use tower::ServiceExt;
@@ -2121,5 +2125,62 @@ mod tests {
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
#[tokio::test]
async fn test_last_delete_song() {
let tm_pool = super::db_mgr::get_pool().await.unwrap();
let db_name = super::db_mgr::generate_db_name().await;
match super::db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap();
super::db_mgr::migrations(&pool).await;
let app = super::init::app(pool).await;
let id = test_data::song_id().await.unwrap();
let uri =
super::format_url_with_value(crate::callers::endpoints::DELETESONG, &id).await;
match app
.clone()
.oneshot(
axum::http::Request::builder()
.method(axum::http::Method::DELETE)
.uri(&uri)
.body(axum::body::Body::empty())
.unwrap(),
)
.await
{
Ok(response) => {
let resp = super::get_resp_data::<
crate::callers::song::response::delete_song::Response,
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Response has no data");
let song_and_coverart = &resp.data[0];
assert_eq!(
id, song_and_coverart.song.id,
"Song Ids do not match {id:?} {:?}",
song_and_coverart.song.id
);
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
}
}
}