From 6c41b66d1ca0856140a906e116289ed7fe5e606e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 8 May 2025 16:54:21 +0200 Subject: [PATCH] Can update inbox entry information --- .../src/controllers/inbox_controller.rs | 15 +++++++++++++++ .../src/controllers/server_controller.rs | 2 +- moneymgr_backend/src/main.rs | 4 ++++ moneymgr_backend/src/services/inbox_service.rs | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/moneymgr_backend/src/controllers/inbox_controller.rs b/moneymgr_backend/src/controllers/inbox_controller.rs index c5a6908..91cd395 100644 --- a/moneymgr_backend/src/controllers/inbox_controller.rs +++ b/moneymgr_backend/src/controllers/inbox_controller.rs @@ -41,3 +41,18 @@ pub async fn get_list(auth: AuthExtractor, query: web::Query) -> pub async fn get_single(entry: InboxEntryInPath) -> HttpResult { Ok(HttpResponse::Ok().json(entry.as_ref())) } + +/// Update a single inbox entry information +pub async fn update( + auth: AuthExtractor, + inbox_entry: InboxEntryInPath, + req: web::Json, +) -> HttpResult { + if let Some(err) = req.check_error(auth.user_id()).await? { + return Ok(HttpResponse::BadRequest().json(err)); + } + + inbox_service::update(inbox_entry.as_ref().id(), &req).await?; + + Ok(HttpResponse::Ok().json(inbox_service::get_by_id(inbox_entry.as_ref().id()).await?)) +} diff --git a/moneymgr_backend/src/controllers/server_controller.rs b/moneymgr_backend/src/controllers/server_controller.rs index 11b3251..8078184 100644 --- a/moneymgr_backend/src/controllers/server_controller.rs +++ b/moneymgr_backend/src/controllers/server_controller.rs @@ -54,7 +54,7 @@ impl Default for ServerConstraints { token_max_inactivity: LenConstraints::new(3600, 3600 * 24 * 365), account_name: LenConstraints::not_empty(50), movement_label: LenConstraints::not_empty(200), - inbox_entry_label: LenConstraints::not_empty(200), + inbox_entry_label: LenConstraints::max_only(200), file_allowed_types: &[ "image/jpeg", "image/png", diff --git a/moneymgr_backend/src/main.rs b/moneymgr_backend/src/main.rs index b81ea9c..033b1e4 100644 --- a/moneymgr_backend/src/main.rs +++ b/moneymgr_backend/src/main.rs @@ -162,6 +162,10 @@ async fn main() -> std::io::Result<()> { "/api/inbox/{inbox_id}", web::get().to(inbox_controller::get_single), ) + .route( + "/api/inbox/{inbox_id}", + web::put().to(inbox_controller::update), + ) // 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 6fd610e..b3b3282 100644 --- a/moneymgr_backend/src/services/inbox_service.rs +++ b/moneymgr_backend/src/services/inbox_service.rs @@ -25,7 +25,7 @@ impl UpdateInboxEntryQuery { // Check inbox entry label if let Some(label) = &self.label { if !constraints.inbox_entry_label.check_str(label) { - return Ok(Some("Invalid inbox entry label length!")); + return Ok(Some("Invalid inbox entry label length!")); } }