From c205a2a97da350fd3efe67501cef01a46b45a631 Mon Sep 17 00:00:00 2001 From: Egor Berezovskiy Date: Fri, 8 Nov 2024 10:46:15 +0100 Subject: [PATCH] editoast: stdcm add validation to consist value Signed-off-by: Egor Berezovskiy --- editoast/src/views/timetable/stdcm.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/editoast/src/views/timetable/stdcm.rs b/editoast/src/views/timetable/stdcm.rs index f92a64d75b8..535e026fde6 100644 --- a/editoast/src/views/timetable/stdcm.rs +++ b/editoast/src/views/timetable/stdcm.rs @@ -24,6 +24,7 @@ use std::sync::Arc; use thiserror::Error; use utoipa::IntoParams; use utoipa::ToSchema; +use validator::Validate; use super::SelectionSettings; use crate::core::conflict_detection::ConflictDetectionRequest; @@ -87,7 +88,7 @@ enum STDCMError { } /// An STDCM request -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema, Validate)] pub struct STDCMRequestPayload { /// Deprecated, first step arrival time should be used instead start_time: Option>, @@ -124,10 +125,13 @@ pub struct STDCMRequestPayload { #[schema(value_type = Option, example = json!(["5%", "2min/100km"]))] margin: Option, /// Total mass of the consist in kg + #[validate(range(min = 1.0))] total_mass: Option, /// Total length of the consist in meters + #[validate(range(min = 1.0))] total_length: Option, /// Maximum speed of the consist in km/h + #[validate(range(min = 1.0))] max_speed: Option, loading_gauge_type: Option, } @@ -192,6 +196,8 @@ async fn stdcm( return Err(AuthorizationError::Unauthorized.into()); } + stdcm_request.validate()?; + let db_pool = app_state.db_pool_v2.clone(); let conn = &mut db_pool.get().await?;