From b1dc53e8f24ccad5d68bb1fb7bfcad4d0dcd0b3e Mon Sep 17 00:00:00 2001 From: hamz2a Date: Thu, 21 Nov 2024 15:36:40 +0100 Subject: [PATCH] editoast: refactor: renamed many structs for consistency Signed-off-by: hamz2a --- editoast/src/core/stdcm.rs | 12 ++++++------ editoast/src/views/timetable/stdcm.rs | 3 +-- editoast/src/views/timetable/stdcm/request.rs | 8 +++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/editoast/src/core/stdcm.rs b/editoast/src/core/stdcm.rs index 924ef990568..19703288fee 100644 --- a/editoast/src/core/stdcm.rs +++ b/editoast/src/core/stdcm.rs @@ -20,7 +20,7 @@ use crate::core::AsCoreRequest; use crate::core::Json; #[derive(Debug, Serialize)] -pub struct STDCMRequest { +pub struct Request { /// Infrastructure id pub infra: i64, /// Infrastructure expected version @@ -28,7 +28,7 @@ pub struct STDCMRequest { // Pathfinding inputs /// List of waypoints. Each waypoint is a list of track offset. - pub path_items: Vec, + pub path_items: Vec, /// The loading gauge of the rolling stock pub rolling_stock_loading_gauge: LoadingGaugeType, /// List of supported signaling systems @@ -62,18 +62,18 @@ pub struct STDCMRequest { } #[derive(Debug, Serialize)] -pub struct STDCMPathItem { +pub struct PathItem { /// The track offsets of the path item pub locations: Vec, /// Stop duration in milliseconds. None if the train does not stop at this path item. pub stop_duration: Option, /// If specified, describes when the train may arrive at the location - pub step_timing_data: Option, + pub step_timing_data: Option, } /// Contains the data of a step timing, when it is specified #[derive(Debug, Serialize)] -pub struct STDCMStepTimingData { +pub struct StepTimingData { /// Time the train should arrive at this point pub arrival_time: DateTime, /// Tolerance for the arrival time, when it arrives before the expected time, in ms @@ -131,7 +131,7 @@ pub enum Response { }, } -impl AsCoreRequest> for STDCMRequest { +impl AsCoreRequest> for Request { const METHOD: reqwest::Method = reqwest::Method::POST; const URL_PATH: &'static str = "/v2/stdcm"; diff --git a/editoast/src/views/timetable/stdcm.rs b/editoast/src/views/timetable/stdcm.rs index 5f15444605a..a906dc57990 100644 --- a/editoast/src/views/timetable/stdcm.rs +++ b/editoast/src/views/timetable/stdcm.rs @@ -33,7 +33,6 @@ use crate::core::pathfinding::InvalidPathItem; use crate::core::pathfinding::PathfindingResultSuccess; use crate::core::simulation::PhysicsConsistParameters; use crate::core::simulation::{RoutingRequirement, SimulationResponse, SpacingRequirement}; -use crate::core::stdcm::STDCMRequest; use crate::core::AsCoreRequest; use crate::core::CoreClient; use crate::error::Result; @@ -210,7 +209,7 @@ async fn stdcm( let work_schedules = stdcm_request.get_work_schedules(conn).await?; // 5. Build STDCM request - let stdcm_request = STDCMRequest { + let stdcm_request = crate::core::stdcm::Request { infra: infra.id, expected_version: infra.version.clone(), rolling_stock_loading_gauge: rolling_stock.loading_gauge, diff --git a/editoast/src/views/timetable/stdcm/request.rs b/editoast/src/views/timetable/stdcm/request.rs index cb46a42f57c..5c3ef3bfbe2 100644 --- a/editoast/src/views/timetable/stdcm/request.rs +++ b/editoast/src/views/timetable/stdcm/request.rs @@ -13,8 +13,6 @@ use serde::Serialize; use utoipa::ToSchema; use crate::core::pathfinding::PathfindingInputError; -use crate::core::stdcm::STDCMPathItem; -use crate::core::stdcm::STDCMStepTimingData; use crate::error::Result; use crate::models::temporary_speed_limits::TemporarySpeedLimit; use crate::models::towed_rolling_stock::TowedRollingStockModel; @@ -224,7 +222,7 @@ impl Request { &self, conn: &mut DbConnection, infra_id: i64, - ) -> Result> { + ) -> Result> { let locations: Vec<_> = self.steps.iter().map(|item| &item.location).collect(); let path_item_cache = PathItemCache::load(conn, infra_id, &locations).await?; @@ -240,11 +238,11 @@ impl Request { Ok(track_offsets .iter() .zip(&self.steps) - .map(|(track_offset, path_item)| STDCMPathItem { + .map(|(track_offset, path_item)| crate::core::stdcm::PathItem { stop_duration: path_item.duration, locations: track_offset.to_vec(), step_timing_data: path_item.timing_data.as_ref().map(|timing_data| { - STDCMStepTimingData { + crate::core::stdcm::StepTimingData { arrival_time: timing_data.arrival_time, arrival_time_tolerance_before: timing_data.arrival_time_tolerance_before, arrival_time_tolerance_after: timing_data.arrival_time_tolerance_after,