@@ -52,7 +52,7 @@ editoast_common::schemas! {
52
52
53
53
/// Path input is described by some rolling stock information
54
54
/// and a list of path waypoints
55
- #[ derive( Deserialize , Clone , Debug , Hash , ToSchema ) ]
55
+ #[ derive( Clone , Debug , Hash , ToSchema ) ]
56
56
struct PathfindingInput {
57
57
/// The loading gauge of the rolling stock
58
58
rolling_stock_loading_gauge : LoadingGaugeType ,
@@ -73,6 +73,45 @@ struct PathfindingInput {
73
73
rolling_stock_length : OrderedFloat < f64 > ,
74
74
}
75
75
76
+ impl < ' de > Deserialize < ' de > for PathfindingInput {
77
+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
78
+ where
79
+ D : serde:: Deserializer < ' de > {
80
+ #[ derive( Deserialize ) ]
81
+ #[ serde( deny_unknown_fields) ]
82
+ struct Internal {
83
+ rolling_stock_loading_gauge : LoadingGaugeType ,
84
+ rolling_stock_is_thermal : bool ,
85
+ rolling_stock_supported_electrifications : Vec < String > ,
86
+ rolling_stock_supported_signaling_systems : Vec < String > ,
87
+ path_items : Vec < PathItemLocation > ,
88
+ rolling_stock_maximum_speed : OrderedFloat < f64 > ,
89
+ rolling_stock_length : OrderedFloat < f64 > ,
90
+ }
91
+ let Internal {
92
+ rolling_stock_loading_gauge,
93
+ rolling_stock_is_thermal,
94
+ rolling_stock_supported_electrifications,
95
+ rolling_stock_supported_signaling_systems,
96
+ path_items,
97
+ rolling_stock_maximum_speed,
98
+ rolling_stock_length,
99
+ } = Internal :: deserialize ( deserializer) ?;
100
+ if path_items. get ( path_items. len ( ) - 1 ) == path_items. get ( 0 ) {
101
+ return Err ( serde:: de:: Error :: custom ( "First and last path items cannot be the same" ) ) ;
102
+ }
103
+ Ok ( PathfindingInput {
104
+ rolling_stock_loading_gauge,
105
+ rolling_stock_is_thermal,
106
+ rolling_stock_supported_electrifications,
107
+ rolling_stock_supported_signaling_systems,
108
+ path_items,
109
+ rolling_stock_maximum_speed,
110
+ rolling_stock_length,
111
+ } )
112
+ }
113
+ }
114
+
76
115
#[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , ToSchema ) ]
77
116
#[ serde( tag = "status" , rename_all = "snake_case" ) ]
78
117
pub enum PathfindingResult {
@@ -448,6 +487,29 @@ pub mod tests {
448
487
use crate :: views:: path:: pathfinding:: PathfindingResult ;
449
488
use crate :: views:: test_app:: TestAppBuilder ;
450
489
490
+ #[ rstest]
491
+ async fn pathfinding_with_same_origin_and_destination_fails ( ) {
492
+ let app = TestAppBuilder :: default_app ( ) ;
493
+ let db_pool = app. db_pool ( ) ;
494
+ let small_infra = create_small_infra ( & mut db_pool. get_ok ( ) ) . await ;
495
+
496
+ let request = app
497
+ . post ( format ! ( "/infra/{}/pathfinding/blocks" , small_infra. id) . as_str ( ) )
498
+ . json ( & json ! ( {
499
+ "path_items" : [
500
+ { "trigram" : "WS" , "secondary_code" : "BV" } ,
501
+ { "trigram" : "WS" , "secondary_code" : "BV" } ,
502
+ ] ,
503
+ "rolling_stock_is_thermal" : true ,
504
+ "rolling_stock_loading_gauge" : "G1" ,
505
+ "rolling_stock_supported_electrifications" : [ ] ,
506
+ "rolling_stock_supported_signaling_systems" : [ "BAL" , "BAPR" ] ,
507
+ "rolling_stock_maximum_speed" : 22.00 ,
508
+ "rolling_stock_length" : 26.00
509
+ } ) ) ;
510
+ app. fetch ( request) . assert_status ( StatusCode :: UNPROCESSABLE_ENTITY ) ;
511
+ }
512
+
451
513
#[ rstest]
452
514
async fn pathfinding_with_invalid_path_items_returns_invalid_path_items ( ) {
453
515
let app = TestAppBuilder :: default_app ( ) ;
0 commit comments