Skip to content

Commit a171352

Browse files
committed
editoast: move get_towed_rolling_stock to STDCMRequestPayload
Signed-off-by: hamz2a <[email protected]>
1 parent ebf9bed commit a171352

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

editoast/src/views/timetable/stdcm.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use crate::core::AsCoreRequest;
3636
use crate::core::CoreClient;
3737
use crate::error::Result;
3838
use crate::models::timetable::TimetableWithTrains;
39-
use crate::models::towed_rolling_stock::TowedRollingStockModel;
4039
use crate::models::train_schedule::TrainSchedule;
4140
use crate::models::Infra;
4241
use crate::models::RollingStockModel;
@@ -158,20 +157,6 @@ async fn stdcm(
158157
})
159158
.await?;
160159

161-
let towed_rolling_stock =
162-
if let Some(towed_rolling_stock_id) = stdcm_request.towed_rolling_stock_id {
163-
let towed_rolling_stock =
164-
TowedRollingStockModel::retrieve_or_fail(conn, towed_rolling_stock_id, || {
165-
STDCMError::TowedRollingStockNotFound {
166-
towed_rolling_stock_id,
167-
}
168-
})
169-
.await?;
170-
Some(towed_rolling_stock)
171-
} else {
172-
None
173-
};
174-
175160
// 2. Compute the earliest start time and maximum departure delay
176161
let (virtual_train_schedule, virtual_train_sim_result, virtual_train_pathfinding_result) =
177162
simulate_train_run(
@@ -254,7 +239,10 @@ async fn stdcm(
254239
max_speed: stdcm_request.max_speed,
255240
total_length: stdcm_request.total_length,
256241
total_mass: stdcm_request.total_mass,
257-
towed_rolling_stock: towed_rolling_stock.map(From::from),
242+
towed_rolling_stock: stdcm_request
243+
.get_towed_rolling_stock(conn)
244+
.await?
245+
.map(From::from),
258246
traction_engine: rolling_stock.into(),
259247
}
260248
.into(),

editoast/src/views/timetable/stdcm_request_payload.rs

+21
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ use crate::core::stdcm::STDCMPathItem;
1717
use crate::core::stdcm::STDCMStepTimingData;
1818
use crate::error::Result;
1919
use crate::models::temporary_speed_limits::TemporarySpeedLimit;
20+
use crate::models::towed_rolling_stock::TowedRollingStockModel;
2021
use crate::models::work_schedules::WorkSchedule;
2122
use crate::models::List;
2223
use crate::views::path::path_item_cache::PathItemCache;
2324
use crate::views::path::pathfinding::PathfindingFailure;
2425
use crate::views::path::pathfinding::PathfindingResult;
26+
use crate::Retrieve;
2527
use crate::SelectionSettings;
2628

2729
use super::stdcm::STDCMError;
@@ -261,4 +263,23 @@ impl STDCMRequestPayload {
261263
.filter(move || WorkSchedule::WORK_SCHEDULE_GROUP_ID.eq(work_schedule_group_id));
262264
WorkSchedule::list(conn, selection_setting).await
263265
}
266+
267+
pub async fn get_towed_rolling_stock(
268+
&self,
269+
conn: &mut DbConnection,
270+
) -> Result<Option<TowedRollingStockModel>> {
271+
if self.towed_rolling_stock_id.is_none() {
272+
return Ok(None);
273+
}
274+
275+
let towed_rolling_stock_id = self.towed_rolling_stock_id.unwrap();
276+
let towed_rolling_stock =
277+
TowedRollingStockModel::retrieve_or_fail(conn, towed_rolling_stock_id, || {
278+
STDCMError::TowedRollingStockNotFound {
279+
towed_rolling_stock_id,
280+
}
281+
})
282+
.await?;
283+
Ok(Some(towed_rolling_stock))
284+
}
264285
}

0 commit comments

Comments
 (0)