From 163c97b2f5cfc8e5c4ef6a33e2ef61c6109c2857 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 29 Mar 2024 21:46:15 +0100 Subject: [PATCH] proper log for registering guests --- src/model/usertrip.rs | 4 ++-- src/tera/planned.rs | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/model/usertrip.rs b/src/model/usertrip.rs index 47603dc..e2a510c 100644 --- a/src/model/usertrip.rs +++ b/src/model/usertrip.rs @@ -11,7 +11,7 @@ impl UserTrip { user: &User, trip_details: &TripDetails, user_note: Option, - ) -> Result<(), UserTripError> { + ) -> Result { if trip_details.is_full(db).await { return Err(UserTripError::EventAlreadyFull); } @@ -81,7 +81,7 @@ impl UserTrip { .await; } - Ok(()) + Ok(name_newly_registered_person) } pub async fn delete( diff --git a/src/tera/planned.rs b/src/tera/planned.rs index 468bd05..785b9b3 100644 --- a/src/tera/planned.rs +++ b/src/tera/planned.rs @@ -63,15 +63,25 @@ async fn join( }; match UserTrip::create(db, &user, &trip_details, user_note).await { - Ok(_) => { - Log::create( - db, - format!( - "User {} registered for trip_details.id={}", - user.name, trip_details_id - ), - ) - .await; + Ok(registered_user) => { + if registered_user == user.name { + Log::create( + db, + format!( + "User {} registered for trip_details.id={}", + user.name, trip_details_id + ), + ) + .await; + }else{ + Log::create( + db, + format!( + "User {} registered the guest '{}' for trip_details.id={}", + user.name, registered_user, trip_details_id + ), + ).await; + } Flash::success(Redirect::to("/planned"), "Erfolgreich angemeldet!") } Err(UserTripError::EventAlreadyFull) => {