From 1515f50ed9a3c38ae8cd86edf4460d4aec70c978 Mon Sep 17 00:00:00 2001 From: Max Hohlfeld Date: Tue, 8 Jul 2025 16:07:26 +0200 Subject: [PATCH] fix: empty comment gets saved --- web/src/endpoints/availability/post_new.rs | 7 ++++++- web/src/endpoints/availability/post_update.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/web/src/endpoints/availability/post_new.rs b/web/src/endpoints/availability/post_new.rs index 7e0602da..9e2f46df 100644 --- a/web/src/endpoints/availability/post_new.rs +++ b/web/src/endpoints/availability/post_new.rs @@ -26,9 +26,14 @@ pub async fn post( availability: None, }; + let comment = form + .comment + .clone() + .and_then(|c| if !c.trim().is_empty() { Some(c) } else { None }); + let mut changeset = AvailabilityChangeset { time: (start, end), - comment: form.comment.clone(), + comment, }; if let Err(e) = changeset.validate_with_context(&context).await { diff --git a/web/src/endpoints/availability/post_update.rs b/web/src/endpoints/availability/post_update.rs index 30a3a766..443f4864 100644 --- a/web/src/endpoints/availability/post_update.rs +++ b/web/src/endpoints/availability/post_update.rs @@ -29,6 +29,11 @@ pub async fn post( let start = form.startdate.and_time(form.starttime); let end = form.enddate.and_time(form.endtime); + let comment = form + .comment + .clone() + .and_then(|c| if !c.trim().is_empty() { Some(c) } else { None }); + let context = AvailabilityContext { pool: pool.get_ref(), user_id: user.id, @@ -37,7 +42,7 @@ pub async fn post( let mut changeset = AvailabilityChangeset { time: (start, end), - comment: form.comment.clone(), + comment, }; if let Err(e) = changeset.validate_with_context(&context).await {