From cfd0ccc8c2ecc87cfc6103295d47a7239fc08301 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 28 Oct 2023 14:33:22 +0200 Subject: [PATCH] add logs --- src/tera/log.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/tera/log.rs b/src/tera/log.rs index a9178a5..fc4acba 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -162,6 +162,15 @@ async fn create_logbook( data: Form, user: &NonGuestUser, ) -> Flash { + Log::create( + db, + format!( + "User {} tries to create log entry={:?}", + user.user.name, data + ), + ) + .await; + match Logbook::create( db, data.into_inner(), @@ -202,6 +211,15 @@ async fn create_kiosk( _kiosk: KioskCookie, ) -> Flash { let creator = User::find_by_id(db, data.shipmaster as i32).await.unwrap(); + Log::create( + db, + format!( + "Kiosk tries to create log for shipmaster {} entry={:?}", + creator.name, data + ), + ) + .await; + create_logbook(db, data, &NonGuestUser::try_from(creator).unwrap()).await //TODO: fixme } @@ -237,6 +255,13 @@ async fn home_kiosk( _kiosk: KioskCookie, ) -> Flash { let logbook = Logbook::find_by_id(db, logbook_id).await.unwrap(); //TODO: fixme + + Log::create( + db, + format!("Kiosk tries to finish log entry {logbook_id} {data:?}"), + ) + .await; + home_logbook( db, data, @@ -258,6 +283,15 @@ async fn home( logbook_id: i32, user: NonGuestUser, ) -> Flash { + Log::create( + db, + format!( + "User {} tries to finish log entry {logbook_id} {data:?}", + user.user.name + ), + ) + .await; + home_logbook(db, data, logbook_id, &user).await } @@ -265,6 +299,11 @@ async fn home( async fn delete(db: &State, logbook_id: i32, user: User) -> Flash { let logbook = Logbook::find_by_id(db, logbook_id).await; if let Some(logbook) = logbook { + Log::create( + db, + format!("User {} tries to delete log entry {logbook_id}", user.name), + ) + .await; match logbook.delete(db, &user).await { Ok(_) => Flash::success( Redirect::to("/log"), @@ -294,6 +333,7 @@ async fn delete_kiosk( let cox = User::find_by_id(db, logbook.shipmaster as i32) .await .unwrap(); + Log::create(db, format!("Kiosk tries to delete log entry {logbook_id} ")).await; match logbook.delete(db, &cox).await { Ok(_) => Flash::success( Redirect::to("/log"),