diff --git a/moneymgr_backend/src/controllers/inbox_controller.rs b/moneymgr_backend/src/controllers/inbox_controller.rs index 91cd395..6badee3 100644 --- a/moneymgr_backend/src/controllers/inbox_controller.rs +++ b/moneymgr_backend/src/controllers/inbox_controller.rs @@ -56,3 +56,9 @@ pub async fn update( Ok(HttpResponse::Ok().json(inbox_service::get_by_id(inbox_entry.as_ref().id()).await?)) } + +/// Delete a single inbox entry +pub async fn delete(inbox_entry: InboxEntryInPath) -> HttpResult { + inbox_service::delete(inbox_entry.as_ref().id()).await?; + Ok(HttpResponse::Accepted().finish()) +} diff --git a/moneymgr_backend/src/main.rs b/moneymgr_backend/src/main.rs index 033b1e4..6817b80 100644 --- a/moneymgr_backend/src/main.rs +++ b/moneymgr_backend/src/main.rs @@ -166,6 +166,10 @@ async fn main() -> std::io::Result<()> { "/api/inbox/{inbox_id}", web::put().to(inbox_controller::update), ) + .route( + "/api/inbox/{inbox_id}", + web::delete().to(inbox_controller::delete), + ) // Statistics controller .route("/api/stats/global", web::get().to(stats_controller::global)) .route( diff --git a/moneymgr_backend/src/services/inbox_service.rs b/moneymgr_backend/src/services/inbox_service.rs index b3b3282..35a1512 100644 --- a/moneymgr_backend/src/services/inbox_service.rs +++ b/moneymgr_backend/src/services/inbox_service.rs @@ -105,3 +105,9 @@ pub async fn get_by_id(entry_id: InboxEntryID) -> anyhow::Result { .filter(inbox::dsl::id.eq(entry_id.0)) .get_result(&mut db()?)?) } + +/// Delete an inbox entry +pub async fn delete(id: InboxEntryID) -> anyhow::Result<()> { + diesel::delete(inbox::dsl::inbox.filter(inbox::dsl::id.eq(id.0))).execute(&mut db()?)?; + Ok(()) +}