diff --git a/ffplayout-api/src/api/routes.rs b/ffplayout-api/src/api/routes.rs index 6e63b490..407a220c 100644 --- a/ffplayout-api/src/api/routes.rs +++ b/ffplayout-api/src/api/routes.rs @@ -817,7 +817,7 @@ pub async fn save_playlist( data: web::Json, ) -> Result { match write_playlist(&pool.into_inner(), *id, data.into_inner()).await { - Ok(res) => Ok(res), + Ok(res) => Ok(web::Json(res)), Err(e) => Err(e), } } @@ -885,7 +885,7 @@ pub async fn del_playlist( params: web::Path<(i32, String)>, ) -> Result { match delete_playlist(&pool.into_inner(), params.0, ¶ms.1).await { - Ok(_) => Ok(format!("Delete playlist from {} success!", params.1)), + Ok(m) => Ok(web::Json(m)), Err(e) => Err(e), } } diff --git a/ffplayout-api/src/utils/playlist.rs b/ffplayout-api/src/utils/playlist.rs index fcbd8b96..732cae3d 100644 --- a/ffplayout-api/src/utils/playlist.rs +++ b/ffplayout-api/src/utils/playlist.rs @@ -114,7 +114,11 @@ pub async fn generate_playlist( } } -pub async fn delete_playlist(conn: &Pool, id: i32, date: &str) -> Result<(), ServiceError> { +pub async fn delete_playlist( + conn: &Pool, + id: i32, + date: &str, +) -> Result { let (config, _) = playout_config(conn, &id).await?; let mut playlist_path = PathBuf::from(&config.playlist.path); let d: Vec<&str> = date.split('-').collect(); @@ -125,11 +129,14 @@ pub async fn delete_playlist(conn: &Pool, id: i32, date: &str) -> Result .with_extension("json"); if playlist_path.is_file() { - if let Err(e) = fs::remove_file(playlist_path) { - error!("{e}"); - return Err(ServiceError::InternalServerError); + match fs::remove_file(playlist_path) { + Ok(_) => return Ok(format!("Delete playlist from {date} success!")), + Err(e) => { + error!("{e}"); + return Err(ServiceError::InternalServerError); + } }; + } else { + Ok(format!("No playlist to delete on: {date}")) } - - Ok(()) }