Skip to content

Commit

Permalink
editoast: stdcm - add validation to consist value
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Nov 8, 2024
1 parent 37165ae commit 09f5d66
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DateTime<Utc>>,
Expand Down Expand Up @@ -124,10 +125,13 @@ pub struct STDCMRequestPayload {
#[schema(value_type = Option<String>, example = json!(["5%", "2min/100km"]))]
margin: Option<MarginValue>,
/// Total mass of the consist in kg
#[validate(range(min = 1.0))]
total_mass: Option<f64>,
/// Total length of the consist in meters
#[validate(range(min = 1.0))]
total_length: Option<f64>,
/// Maximum speed of the consist in km/h
#[validate(range(min = 1.0))]
max_speed: Option<f64>,
loading_gauge_type: Option<LoadingGaugeType>,
}
Expand Down Expand Up @@ -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?;

Expand Down

0 comments on commit 09f5d66

Please sign in to comment.