add debug trait; switch to proper name of form field (rowerS)

This commit is contained in:
philipp 2023-09-23 18:12:48 +02:00
parent 52b6dc4e09
commit 1f801b0436
2 changed files with 9 additions and 8 deletions

View File

@ -26,7 +26,7 @@ impl PartialEq for Logbook {
} }
} }
#[derive(FromForm)] #[derive(FromForm, Debug)]
pub struct LogToAdd { pub struct LogToAdd {
pub boat_id: i32, pub boat_id: i32,
pub shipmaster: i64, pub shipmaster: i64,
@ -37,7 +37,7 @@ pub struct LogToAdd {
pub distance_in_km: Option<i64>, pub distance_in_km: Option<i64>,
pub comments: Option<String>, pub comments: Option<String>,
pub logtype: Option<i64>, pub logtype: Option<i64>,
pub rower: Vec<i64>, pub rowers: Vec<i64>,
} }
#[derive(FromForm)] #[derive(FromForm)]
@ -49,7 +49,7 @@ pub struct LogToFinalize {
pub rower: Vec<i64>, pub rower: Vec<i64>,
} }
#[derive(Serialize)] #[derive(Serialize, Debug)]
pub struct LogbookWithBoatAndRowers { pub struct LogbookWithBoatAndRowers {
#[serde(flatten)] #[serde(flatten)]
pub logbook: Logbook, pub logbook: Logbook,
@ -187,14 +187,14 @@ ORDER BY departure DESC
return Err(LogbookCreateError::ShipmasterAlreadyOnWater); 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( return Err(LogbookCreateError::TooManyRowers(
boat.amount_seats as usize, 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(); let user = User::find_by_id(db, *rower as i32).await.unwrap();
if user.on_water(db).await { if user.on_water(db).await {
return Err(LogbookCreateError::RowerAlreadyOnWater(user)); return Err(LogbookCreateError::RowerAlreadyOnWater(user));
@ -204,7 +204,6 @@ ORDER BY departure DESC
let mut tx = db.begin().await.unwrap(); let mut tx = db.begin().await.unwrap();
let departure = NaiveDateTime::parse_from_str(&log.departure, "%Y-%m-%dT%H:%M").unwrap(); let departure = NaiveDateTime::parse_from_str(&log.departure, "%Y-%m-%dT%H:%M").unwrap();
println!("@@@@@@ {:?}", log.arrival);
let arrival = log let arrival = log
.arrival .arrival
.map(|a| NaiveDateTime::parse_from_str(&a, "%Y-%m-%dT%H:%M").unwrap()); .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) .fetch_one(&mut tx)
.await.unwrap(); .await.unwrap();
for rower in &log.rower { for rower in &log.rowers {
Rower::create(&mut tx, inserted_row.id, *rower) Rower::create(&mut tx, inserted_row.id, *rower)
.await .await
.map_err(|e| LogbookCreateError::RowerCreateError(*rower, e.to_string()))?; .map_err(|e| LogbookCreateError::RowerCreateError(*rower, e.to_string()))?;

View File

@ -48,6 +48,8 @@ async fn index(
let on_water = Logbook::on_water(db).await; let on_water = Logbook::on_water(db).await;
println!("{on_water:?}");
let mut context = Context::new(); let mut context = Context::new();
if let Some(msg) = flash { if let Some(msg) = flash {
context.insert("flash", &msg.into_inner()); context.insert("flash", &msg.into_inner());