From c6a8866207c0c913775aaa8c5d63160058079c39 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 23 Sep 2023 18:12:48 +0200 Subject: [PATCH] add debug trait; switch to proper name of form field (rowerS) --- src/model/logbook.rs | 15 +++++++-------- src/tera/log.rs | 2 ++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/model/logbook.rs b/src/model/logbook.rs index e38e1b8..2f48c1b 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -26,7 +26,7 @@ impl PartialEq for Logbook { } } -#[derive(FromForm)] +#[derive(FromForm, Debug)] pub struct LogToAdd { pub boat_id: i32, pub shipmaster: i64, @@ -37,7 +37,7 @@ pub struct LogToAdd { pub distance_in_km: Option, pub comments: Option, pub logtype: Option, - pub rower: Vec, + pub rowers: Vec, } #[derive(FromForm)] @@ -49,7 +49,7 @@ pub struct LogToFinalize { pub rower: Vec, } -#[derive(Serialize)] +#[derive(Serialize, Debug)] pub struct LogbookWithBoatAndRowers { #[serde(flatten)] pub logbook: Logbook, @@ -187,14 +187,14 @@ ORDER BY departure DESC return Err(LogbookCreateError::ShipmasterAlreadyOnWater); } - if log.rower.len() > boat.amount_seats as usize - 1 { + if log.rowers.len() > boat.amount_seats as usize - 1 { return Err(LogbookCreateError::TooManyRowers( boat.amount_seats as usize, - log.rower.len() + 1, + log.rowers.len() + 1, )); } - for rower in &log.rower { + for rower in &log.rowers { let user = User::find_by_id(db, *rower as i32).await.unwrap(); if user.on_water(db).await { return Err(LogbookCreateError::RowerAlreadyOnWater(user)); @@ -204,7 +204,6 @@ ORDER BY departure DESC let mut tx = db.begin().await.unwrap(); let departure = NaiveDateTime::parse_from_str(&log.departure, "%Y-%m-%dT%H:%M").unwrap(); - println!("@@@@@@ {:?}", log.arrival); let arrival = log .arrival .map(|a| NaiveDateTime::parse_from_str(&a, "%Y-%m-%dT%H:%M").unwrap()); @@ -223,7 +222,7 @@ ORDER BY departure DESC .fetch_one(&mut tx) .await.unwrap(); - for rower in &log.rower { + for rower in &log.rowers { Rower::create(&mut tx, inserted_row.id, *rower) .await .map_err(|e| LogbookCreateError::RowerCreateError(*rower, e.to_string()))?; diff --git a/src/tera/log.rs b/src/tera/log.rs index 7eb3c2f..8709ac9 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -48,6 +48,8 @@ async fn index( let on_water = Logbook::on_water(db).await; + println!("{on_water:?}"); + let mut context = Context::new(); if let Some(msg) = flash { context.insert("flash", &msg.into_inner());