@@ -28,14 +28,16 @@ use super::path_not_found_handler::PathNotFoundHandler;
28
28
use super :: stdcm_request_payload:: convert_steps;
29
29
use super :: stdcm_request_payload:: STDCMRequestPayload ;
30
30
use super :: SelectionSettings ;
31
+ use crate :: core:: conflict_detection:: Conflict ;
31
32
use crate :: core:: conflict_detection:: TrainRequirements ;
32
33
use crate :: core:: pathfinding:: InvalidPathItem ;
33
34
use crate :: core:: pathfinding:: PathfindingInputError ;
35
+ use crate :: core:: pathfinding:: PathfindingResultSuccess ;
34
36
use crate :: core:: simulation:: PhysicsRollingStock ;
35
37
use crate :: core:: simulation:: { RoutingRequirement , SimulationResponse , SpacingRequirement } ;
38
+ use crate :: core:: stdcm:: STDCMCoreResponse ;
36
39
use crate :: core:: stdcm:: STDCMPathItem ;
37
40
use crate :: core:: stdcm:: STDCMRequest ;
38
- use crate :: core:: stdcm:: STDCMResponse ;
39
41
use crate :: core:: stdcm:: STDCMStepTimingData ;
40
42
use crate :: core:: AsCoreRequest ;
41
43
use crate :: core:: CoreClient ;
@@ -62,6 +64,26 @@ crate::routes! {
62
64
"/stdcm" => stdcm,
63
65
}
64
66
67
+ #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , ToSchema ) ]
68
+ #[ serde( tag = "status" , rename_all = "snake_case" ) ]
69
+ // We accepted the difference of memory size taken by variants
70
+ // Since there is only on success and others are error cases
71
+ #[ allow( clippy:: large_enum_variant) ]
72
+ pub enum STDCMResponse {
73
+ Success {
74
+ simulation : SimulationResponse ,
75
+ path : PathfindingResultSuccess ,
76
+ departure_time : DateTime < Utc > ,
77
+ } ,
78
+ Conflicts {
79
+ pathfinding_result : PathfindingResult ,
80
+ conflicts : Vec < Conflict > ,
81
+ } ,
82
+ PreprocessingSimulationError {
83
+ error : SimulationResponse ,
84
+ } ,
85
+ }
86
+
65
87
#[ derive( Debug , Error , EditoastError , Serialize ) ]
66
88
#[ editoast_error( base_id = "stdcm_v2" ) ]
67
89
enum STDCMError {
@@ -247,28 +269,39 @@ async fn stdcm(
247
269
248
270
let stdcm_response = stdcm_request. fetch ( core_client. as_ref ( ) ) . await ?;
249
271
250
- // 8. Handle PathNotFound response of STDCM
251
- if let STDCMResponse :: PathNotFound = stdcm_response {
252
- let path_not_found = PathNotFoundHandler {
253
- core_client,
254
- infra_id,
255
- infra_version : infra. version ,
256
- train_schedules,
257
- simulations,
258
- work_schedules,
259
- virtual_train_schedule,
260
- virtual_train_sim_result,
261
- virtual_train_pathfinding_result,
262
- earliest_departure_time,
263
- maximum_run_time,
264
- latest_simulation_end,
265
- } ;
266
- let stdcm_response = path_not_found. handle ( ) . await ?;
267
-
268
- return Ok ( Json ( stdcm_response) ) ;
272
+ // 8. Handle STDCM Core Response
273
+ match stdcm_response {
274
+ STDCMCoreResponse :: Success {
275
+ simulation,
276
+ path,
277
+ departure_time,
278
+ } => Ok ( Json ( STDCMResponse :: Success {
279
+ simulation,
280
+ path,
281
+ departure_time,
282
+ } ) ) ,
283
+ STDCMCoreResponse :: PreprocessingSimulationError { error } => {
284
+ Ok ( Json ( STDCMResponse :: PreprocessingSimulationError { error } ) )
285
+ }
286
+ STDCMCoreResponse :: PathNotFound => {
287
+ let path_not_found = PathNotFoundHandler {
288
+ core_client,
289
+ infra_id,
290
+ infra_version : infra. version ,
291
+ train_schedules,
292
+ simulations,
293
+ work_schedules,
294
+ virtual_train_schedule,
295
+ virtual_train_sim_result,
296
+ virtual_train_pathfinding_result,
297
+ earliest_departure_time,
298
+ maximum_run_time,
299
+ latest_simulation_end,
300
+ } ;
301
+ let stdcm_response = path_not_found. handle ( ) . await ?;
302
+ Ok ( Json ( stdcm_response) )
303
+ }
269
304
}
270
-
271
- Ok ( Json ( stdcm_response) )
272
305
}
273
306
274
307
/// Build the list of scheduled train requirements, only including requirements
@@ -520,7 +553,6 @@ mod tests {
520
553
use crate :: core:: simulation:: SimulationParameters ;
521
554
use crate :: core:: simulation:: SimulationResponse ;
522
555
use crate :: core:: simulation:: SpeedLimitProperties ;
523
- use crate :: core:: stdcm:: STDCMResponse ;
524
556
use crate :: models:: fixtures:: create_fast_rolling_stock;
525
557
use crate :: models:: fixtures:: create_small_infra;
526
558
use crate :: models:: fixtures:: create_timetable;
0 commit comments