error if same person selected as cox + rower
This commit is contained in:
parent
78d169e056
commit
e849b6f5f9
@ -76,6 +76,7 @@ pub enum LogbookCreateError {
|
|||||||
ShipmasterAlreadyOnWater,
|
ShipmasterAlreadyOnWater,
|
||||||
RowerAlreadyOnWater(User),
|
RowerAlreadyOnWater(User),
|
||||||
RowerCreateError(i64, String),
|
RowerCreateError(i64, String),
|
||||||
|
SamePersonShipmasterAndRower,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Logbook {
|
impl Logbook {
|
||||||
@ -196,6 +197,10 @@ ORDER BY departure DESC
|
|||||||
|
|
||||||
for rower in &log.rowers {
|
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 *rower == log.shipmaster {
|
||||||
|
return Err(LogbookCreateError::SamePersonShipmasterAndRower);
|
||||||
|
}
|
||||||
|
|
||||||
if user.on_water(db).await {
|
if user.on_water(db).await {
|
||||||
return Err(LogbookCreateError::RowerAlreadyOnWater(user));
|
return Err(LogbookCreateError::RowerAlreadyOnWater(user));
|
||||||
}
|
}
|
||||||
@ -487,6 +492,30 @@ mod test {
|
|||||||
assert_eq!(res, Err(LogbookCreateError::ShipmasterAlreadyOnWater));
|
assert_eq!(res, Err(LogbookCreateError::ShipmasterAlreadyOnWater));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[sqlx::test]
|
||||||
|
fn test_create_same_person_cox_and_rower() {
|
||||||
|
let pool = testdb!();
|
||||||
|
|
||||||
|
let res = Logbook::create(
|
||||||
|
&pool,
|
||||||
|
LogToAdd {
|
||||||
|
boat_id: 3,
|
||||||
|
shipmaster: 5,
|
||||||
|
shipmaster_only_steering: false,
|
||||||
|
departure: "2128-05-20T12:00".into(),
|
||||||
|
arrival: None,
|
||||||
|
destination: None,
|
||||||
|
distance_in_km: None,
|
||||||
|
comments: None,
|
||||||
|
logtype: None,
|
||||||
|
rowers: vec![5],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert_eq!(res, Err(LogbookCreateError::SamePersonShipmasterAndRower));
|
||||||
|
}
|
||||||
|
|
||||||
#[sqlx::test]
|
#[sqlx::test]
|
||||||
fn test_create_too_many_rowers() {
|
fn test_create_too_many_rowers() {
|
||||||
let pool = testdb!();
|
let pool = testdb!();
|
||||||
|
@ -145,6 +145,7 @@ async fn create_logbook(db: &SqlitePool, data: Form<LogToAdd>) -> Flash<Redirect
|
|||||||
Err(LogbookCreateError::BoatNotFound) => Flash::error(Redirect::to("/log"), format!("Boot gibt's ned")),
|
Err(LogbookCreateError::BoatNotFound) => Flash::error(Redirect::to("/log"), format!("Boot gibt's ned")),
|
||||||
Err(LogbookCreateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")),
|
Err(LogbookCreateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")),
|
||||||
Err(LogbookCreateError::RowerCreateError(rower, e)) => Flash::error(Redirect::to("/log"), format!("Fehler bei Ruderer {rower}: {e}")),
|
Err(LogbookCreateError::RowerCreateError(rower, e)) => Flash::error(Redirect::to("/log"), format!("Fehler bei Ruderer {rower}: {e}")),
|
||||||
|
Err(LogbookCreateError::SamePersonShipmasterAndRower) => Flash::error(Redirect::to("/log"), format!("Selbe Person als Schiffsführer und Ruderer ausgewählt")),
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user