only allow realistic values for logbook entries
This commit is contained in:
@ -104,6 +104,7 @@ pub enum LogbookUpdateError {
|
||||
SteeringPersonNotInRowers,
|
||||
UserNotAllowedToUseBoat,
|
||||
OnlyAllowedToEndTripsEndingToday,
|
||||
TooFast(i64, i64),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -127,6 +128,7 @@ pub enum LogbookCreateError {
|
||||
ArrivalSetButNotRemainingTwo,
|
||||
OnlyAllowedToEndTripsEndingToday,
|
||||
CantChangeHandoperatableStatusForThisBoat,
|
||||
TooFast(i64, i64),
|
||||
}
|
||||
|
||||
impl From<LogbookUpdateError> for LogbookCreateError {
|
||||
@ -150,6 +152,7 @@ impl From<LogbookUpdateError> for LogbookCreateError {
|
||||
LogbookUpdateError::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() {
|
||||
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 day_diff = today - arr.date();
|
||||
let day_diff = day_diff.num_days();
|
||||
|
Reference in New Issue
Block a user