From e85238ace94dd8a10570458d6966c7ef97a68450 Mon Sep 17 00:00:00 2001 From: Egor Berezovskiy Date: Fri, 8 Nov 2024 11:37:19 +0100 Subject: [PATCH] editoast: fix pr comments Signed-off-by: Egor Berezovskiy --- editoast/src/core/simulation.rs | 11 +++++------ editoast/src/views/timetable/stdcm/request.rs | 6 +++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/editoast/src/core/simulation.rs b/editoast/src/core/simulation.rs index 9124a6e9b80..0c0b462bf77 100644 --- a/editoast/src/core/simulation.rs +++ b/editoast/src/core/simulation.rs @@ -112,13 +112,12 @@ impl PhysicsConsistParameters { } pub fn compute_max_speed(&self) -> f64 { - match self.max_speed { - Some(0.0) => self.traction_engine.max_speed, - Some(max_speed_parameter) => { + self.max_speed + .filter(|max_speed_parameter| *max_speed_parameter != 0.0) + .map(|max_speed_parameter| { f64::min(self.traction_engine.max_speed, max_speed_parameter) - } - None => self.traction_engine.max_speed, - } + }) + .unwrap_or(self.traction_engine.max_speed) } pub fn compute_startup_acceleration(&self) -> f64 { diff --git a/editoast/src/views/timetable/stdcm/request.rs b/editoast/src/views/timetable/stdcm/request.rs index cb46a42f57c..7f994369a37 100644 --- a/editoast/src/views/timetable/stdcm/request.rs +++ b/editoast/src/views/timetable/stdcm/request.rs @@ -11,6 +11,7 @@ use itertools::Itertools; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; +use validator::Validate; use crate::core::pathfinding::PathfindingInputError; use crate::core::stdcm::STDCMPathItem; @@ -67,7 +68,7 @@ struct StepTimingData { } /// An STDCM request -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Validate, ToSchema)] pub(super) struct Request { /// Deprecated, first step arrival time should be used instead pub(super) start_time: Option>, @@ -104,10 +105,13 @@ pub(super) struct Request { #[schema(value_type = Option, example = json!(["5%", "2min/100km"]))] pub(super) margin: Option, /// Total mass of the consist in kg + #[validate(range(exclusive_min = 0.0))] pub(super) total_mass: Option, /// Total length of the consist in meters + #[validate(range(exclusive_min = 0.0))] pub(super) total_length: Option, /// Maximum speed of the consist in km/h + #[validate(range(exclusive_min = 0.0))] pub(super) max_speed: Option, pub(super) loading_gauge_type: Option, }