Skip to content

Commit e9822c0

Browse files
committed
fixup! editoast: pathfinding: add CI/CH codes to pathfinding response
1 parent 5ef96c5 commit e9822c0

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

editoast/openapi.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ components:
13331333
- suggestion
13341334
- geo
13351335
- sch
1336+
- uic
1337+
- ch
13361338
type: object
13371339
PathfindingPayload:
13381340
description: |-

editoast/src/models/pathfinding.rs

+2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ pub struct PathWaypoint {
185185
))]
186186
#[schema(value_type = GeoJsonPoint)]
187187
pub sch: geojson::Geometry,
188+
#[schema(required)]
188189
pub uic: Option<i64>,
190+
#[schema(required)]
189191
pub ch: Option<String>,
190192
}
191193

editoast/src/views/pathfinding/mod.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -375,20 +375,18 @@ impl Pathfinding {
375375
} else {
376376
steps_duration.next().unwrap()
377377
};
378-
let mut op_name = None;
379-
let mut op_uic = None;
380-
let mut op_ch = None;
381-
let op = waypoint
382-
.id
383-
.as_ref()
384-
.map(|op_id| op_map.get(op_id).expect("unexpected OP id"));
385-
op.and_then(|op| op.extensions.identifier.as_ref())
386-
.map(|ident| {
387-
op_name = Some(ident.name.as_ref().to_owned());
388-
op_uic = Some(ident.uic);
389-
});
390-
op.and_then(|op| op.extensions.sncf.as_ref())
391-
.map(|sncf| op_ch = Some(sncf.ch.to_owned()));
378+
let op_info = waypoint.id.as_ref().map(|op_id| {
379+
let op = op_map.get(op_id).expect("unexpected OP id");
380+
let name = op
381+
.extensions
382+
.identifier
383+
.as_ref()
384+
.map(|ident| ident.name.as_ref().to_owned());
385+
let uic = op.extensions.identifier.as_ref().map(|ident| ident.uic);
386+
let ch = op.extensions.sncf.as_ref().map(|sncf| sncf.ch.to_owned());
387+
(name, uic, ch)
388+
});
389+
let (name, uic, ch) = op_info.unwrap_or_default();
392390
let track = track_map
393391
.get(&waypoint.location.track_section.0)
394392
.expect("unexpected track id");
@@ -405,15 +403,15 @@ impl Pathfinding {
405403
let sch = geos::geojson::Geometry::try_from(sch).unwrap();
406404
PathWaypoint {
407405
id: waypoint.id.clone(),
408-
name: op_name,
406+
name,
409407
location: waypoint.location.clone(),
410408
duration,
411409
path_offset: waypoint.path_offset,
412410
suggestion: waypoint.suggestion,
413411
geo,
414412
sch,
415-
uic: op_uic,
416-
ch: op_ch,
413+
uic,
414+
ch,
417415
}
418416
})
419417
.collect();

tests/tests/test_pathfinding.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"curves": [{"radius": 0.0, "position": 0.0}, {"radius": 0.0, "position": 45549.5653000392}],
5353
"steps": [
5454
{
55-
"ch": None,
5655
"id": None,
5756
"name": None,
5857
"location": {"track_section": "TA2", "offset": 837.033949007362},
@@ -61,10 +60,10 @@
6160
"suggestion": False,
6261
"geo": {"coordinates": [-0.387122554630656, 49.49979999999999], "type": "Point"},
6362
"sch": {"coordinates": [-0.387122554630656, 49.49979999999999], "type": "Point"},
63+
"ch": None,
6464
"uic": None,
6565
},
6666
{
67-
"ch": None,
6867
"id": "Mid_West_station",
6968
"name": "Mid_West_station",
7069
"location": {"track_section": "TC2", "offset": 450.0},
@@ -73,10 +72,10 @@
7372
"suggestion": True,
7473
"geo": {"coordinates": [-0.30369999999999997, 49.4999], "type": "Point"},
7574
"sch": {"coordinates": [-0.30369999999999997, 49.4999], "type": "Point"},
76-
"uic": None,
75+
"ch": "aa",
76+
"uic": 0,
7777
},
7878
{
79-
"ch": None,
8079
"id": "Mid_East_station",
8180
"name": "Mid_East_station",
8281
"location": {"track_section": "TD1", "offset": 14000.0},
@@ -85,10 +84,10 @@
8584
"suggestion": True,
8685
"geo": {"coordinates": [-0.22656, 49.4999], "type": "Point"},
8786
"sch": {"coordinates": [-0.22656, 49.4999], "type": "Point"},
88-
"uic": None,
87+
"ch": "aa",
88+
"uic": 0,
8989
},
9090
{
91-
"ch": None,
9291
"id": None,
9392
"name": None,
9493
"location": {"track_section": "TH1", "offset": 4386.599249046556},
@@ -97,6 +96,7 @@
9796
"suggestion": False,
9897
"geo": {"coordinates": [-0.095104854807785, 49.484], "type": "Point"},
9998
"sch": {"coordinates": [-0.095104854807785, 49.484], "type": "Point"},
99+
"ch": None,
100100
"uic": None,
101101
},
102102
],

0 commit comments

Comments
 (0)