only allow realistic values for logbook entries
This commit is contained in:
		| @@ -104,6 +104,7 @@ pub enum LogbookUpdateError { | |||||||
|     SteeringPersonNotInRowers, |     SteeringPersonNotInRowers, | ||||||
|     UserNotAllowedToUseBoat, |     UserNotAllowedToUseBoat, | ||||||
|     OnlyAllowedToEndTripsEndingToday, |     OnlyAllowedToEndTripsEndingToday, | ||||||
|  |     TooFast(i64, i64), | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, PartialEq)] | #[derive(Debug, PartialEq)] | ||||||
| @@ -127,6 +128,7 @@ pub enum LogbookCreateError { | |||||||
|     ArrivalSetButNotRemainingTwo, |     ArrivalSetButNotRemainingTwo, | ||||||
|     OnlyAllowedToEndTripsEndingToday, |     OnlyAllowedToEndTripsEndingToday, | ||||||
|     CantChangeHandoperatableStatusForThisBoat, |     CantChangeHandoperatableStatusForThisBoat, | ||||||
|  |     TooFast(i64, i64), | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<LogbookUpdateError> for LogbookCreateError { | impl From<LogbookUpdateError> for LogbookCreateError { | ||||||
| @@ -150,6 +152,7 @@ impl From<LogbookUpdateError> for LogbookCreateError { | |||||||
|             LogbookUpdateError::OnlyAllowedToEndTripsEndingToday => { |             LogbookUpdateError::OnlyAllowedToEndTripsEndingToday => { | ||||||
|                 LogbookCreateError::OnlyAllowedToEndTripsEndingToday |                 LogbookCreateError::OnlyAllowedToEndTripsEndingToday | ||||||
|             } |             } | ||||||
|  |             LogbookUpdateError::TooFast(km, min) => LogbookCreateError::TooFast(km, min), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -517,6 +520,17 @@ ORDER BY departure DESC | |||||||
|         if arr.and_utc().timestamp() < dep.and_utc().timestamp() { |         if arr.and_utc().timestamp() < dep.and_utc().timestamp() { | ||||||
|             return Err(LogbookUpdateError::ArrivalNotAfterDeparture); |             return Err(LogbookUpdateError::ArrivalNotAfterDeparture); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         let duration_in_mins = (arr.and_utc().timestamp() - dep.and_utc().timestamp()) / 60; | ||||||
|  |         // Not possible to row < 1 min / 500 m = < 2 min / km | ||||||
|  |         let possible_distance_km = duration_in_mins / 2; | ||||||
|  |         if log.distance_in_km > possible_distance_km { | ||||||
|  |             return Err(LogbookUpdateError::TooFast( | ||||||
|  |                 log.distance_in_km, | ||||||
|  |                 duration_in_mins, | ||||||
|  |             )); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         let today = Local::now().date_naive(); |         let today = Local::now().date_naive(); | ||||||
|         let day_diff = today - arr.date(); |         let day_diff = today - arr.date(); | ||||||
|         let day_diff = day_diff.num_days(); |         let day_diff = day_diff.num_days(); | ||||||
|   | |||||||
| @@ -227,7 +227,7 @@ async fn create_logbook( | |||||||
|         Err(LogbookCreateError::ArrivalSetButNotRemainingTwo) => Flash::error(Redirect::to("/log"), "Ankunftszeit gesetzt aber nicht Distanz + Strecke"), |         Err(LogbookCreateError::ArrivalSetButNotRemainingTwo) => Flash::error(Redirect::to("/log"), "Ankunftszeit gesetzt aber nicht Distanz + Strecke"), | ||||||
|         Err(LogbookCreateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die in der letzten Woche enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), |         Err(LogbookCreateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die in der letzten Woche enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), | ||||||
|         Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat) => Flash::error(Redirect::to("/log"), "Handsteuer-Status dieses Boots kann nicht verändert werden."), |         Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat) => Flash::error(Redirect::to("/log"), "Handsteuer-Status dieses Boots kann nicht verändert werden."), | ||||||
|  |         Err(LogbookCreateError::TooFast(km, min)) => Flash::error(Redirect::to("/log"), format!("KM zu groß für die eingegebene Dauer ({km} km in {min} Minuten). Bitte überprüfe deine Start- und Endzeit und versuche es erneut.")), | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -300,6 +300,7 @@ async fn home_logbook( | |||||||
|         Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"), |         Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"), | ||||||
|         Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")), |         Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")), | ||||||
|         Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die heute enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), |         Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die heute enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), | ||||||
|  |         Err(LogbookUpdateError::TooFast(km, min)) => Flash::error(Redirect::to("/log"), format!("KM zu groß für die eingegebene Dauer ({km} km in {min} Minuten). Bitte überprüfe deine Start- und Endzeit und versuche es erneut.")), | ||||||
|         Err(e) => Flash::error( |         Err(e) => Flash::error( | ||||||
|             Redirect::to("/log"), |             Redirect::to("/log"), | ||||||
|             format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"), |             format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user