Skip to content

Commit 578cc56

Browse files
committed
editoast: move Endpoint and TrackEndpoint to editoast_schemas
1 parent 73c4134 commit 578cc56

File tree

18 files changed

+80
-62
lines changed

18 files changed

+80
-62
lines changed

editoast/editoast_schemas/src/infra.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
mod applicable_directions;
22
mod direction;
33
mod directional_track_range;
4+
mod endpoint;
45
mod side;
56
mod sign;
7+
mod track_endpoint;
68
mod track_location;
79
mod track_offset;
810
mod track_range;
@@ -11,8 +13,10 @@ mod waypoint;
1113
pub use applicable_directions::ApplicableDirections;
1214
pub use direction::Direction;
1315
pub use directional_track_range::DirectionalTrackRange;
16+
pub use endpoint::Endpoint;
1417
pub use side::Side;
1518
pub use sign::Sign;
19+
pub use track_endpoint::TrackEndpoint;
1620
pub use track_location::TrackLocation;
1721
pub use track_offset::TrackOffset;
1822
pub use track_range::TrackRange;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use serde::Deserialize;
2+
use serde::Serialize;
3+
4+
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash)]
5+
#[serde(rename_all = "UPPERCASE")]
6+
pub enum Endpoint {
7+
Begin,
8+
End,
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use derivative::Derivative;
2+
use editoast_common::Identifier;
3+
use serde::Deserialize;
4+
use serde::Serialize;
5+
6+
use super::Direction;
7+
use super::Endpoint;
8+
9+
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
10+
#[derivative(Default)]
11+
#[serde(deny_unknown_fields)]
12+
pub struct TrackEndpoint {
13+
#[derivative(Default(value = "Endpoint::Begin"))]
14+
pub endpoint: Endpoint,
15+
#[derivative(Default(value = r#""InvalidRef".into()"#))]
16+
pub track: Identifier,
17+
}
18+
19+
impl TrackEndpoint {
20+
/// Create a new `TrackEndpoint` from a track id and an endpoint.
21+
pub fn new<T: AsRef<str>>(track: T, endpoint: Endpoint) -> Self {
22+
TrackEndpoint {
23+
track: track.as_ref().into(),
24+
endpoint,
25+
}
26+
}
27+
28+
/// Create a `TrackEndpoint` from a track id and a direction.
29+
pub fn from_track_and_direction<T: AsRef<str>>(track: T, dir: Direction) -> TrackEndpoint {
30+
let endpoint = match dir {
31+
Direction::StartToStop => Endpoint::End,
32+
Direction::StopToStart => Endpoint::Begin,
33+
};
34+
TrackEndpoint {
35+
track: track.as_ref().into(),
36+
endpoint,
37+
}
38+
}
39+
}

editoast/src/converters/generate_routes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::collections::HashMap;
99
use crate::schema::*;
1010
use editoast_common::Identifier;
1111
use editoast_schemas::infra::Direction;
12+
use editoast_schemas::infra::Endpoint;
13+
use editoast_schemas::infra::TrackEndpoint;
1214
use editoast_schemas::infra::Waypoint;
1315
use editoast_schemas::primitives::OSRDIdentified;
1416

editoast/src/converters/osm_to_railjson.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ pub fn parse_osm(osm_pbf_in: PathBuf) -> Result<RailJson, Box<dyn Error + Send +
127127

128128
#[cfg(test)]
129129
mod tests {
130+
use editoast_common::Identifier;
130131
use editoast_schemas::infra::ApplicableDirections;
132+
use editoast_schemas::infra::TrackEndpoint;
131133
use std::collections::HashMap;
132134

133135
use super::parse_osm;
134136
use crate::converters::*;
135137
use crate::schema::*;
136-
use editoast_common::Identifier;
138+
137139
#[test]
138140
fn convert_osm_to_railjson() {
139141
let output = tempfile::NamedTempFile::new().unwrap();

editoast/src/converters/utils.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use editoast_schemas::infra::Direction;
33
use std::collections::HashMap;
44
use std::str::FromStr;
55

6+
use editoast_schemas::infra::Endpoint;
67
use editoast_schemas::infra::Side;
8+
use editoast_schemas::infra::TrackEndpoint;
79
use osm4routing::Coord;
810
use osm4routing::Edge;
911
use osm4routing::NodeId;

editoast/src/generated_data/error/buffer_stops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::generated_data::error::ObjectErrorGenerator;
44
use crate::infra_cache::Graph;
55
use crate::infra_cache::InfraCache;
66
use crate::infra_cache::ObjectCache;
7-
use crate::schema::Endpoint;
87
use crate::schema::InfraError;
9-
use crate::schema::TrackEndpoint;
8+
use editoast_schemas::infra::Endpoint;
9+
use editoast_schemas::infra::TrackEndpoint;
1010
use editoast_schemas::primitives::ObjectRef;
1111
use editoast_schemas::primitives::ObjectType;
1212

@@ -172,7 +172,7 @@ pub mod tests {
172172
use crate::infra_cache::tests::create_small_infra_cache;
173173
use crate::infra_cache::tests::create_track_section_cache;
174174
use crate::infra_cache::Graph;
175-
use crate::schema::Endpoint;
175+
use editoast_schemas::infra::Endpoint;
176176
use editoast_schemas::primitives::ObjectRef;
177177
use editoast_schemas::primitives::ObjectType;
178178

editoast/src/generated_data/error/switches.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::infra_cache::Graph;
66
use crate::infra_cache::InfraCache;
77
use crate::infra_cache::ObjectCache;
88
use crate::schema::InfraError;
9-
use crate::schema::TrackEndpoint;
9+
use editoast_schemas::infra::TrackEndpoint;
1010
use editoast_schemas::primitives::OSRDIdentified;
1111
use editoast_schemas::primitives::ObjectRef;
1212
use editoast_schemas::primitives::ObjectType;
@@ -143,7 +143,7 @@ mod tests {
143143
use crate::infra_cache::tests::create_small_infra_cache;
144144
use crate::infra_cache::tests::create_switch_cache_point;
145145
use crate::infra_cache::tests::create_track_endpoint;
146-
use crate::schema::Endpoint;
146+
use editoast_schemas::infra::Endpoint;
147147
use editoast_schemas::primitives::OSRDIdentified;
148148
use editoast_schemas::primitives::ObjectRef;
149149
use editoast_schemas::primitives::ObjectType;

editoast/src/infra_cache/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::collections::HashMap;
22

33
use crate::infra_cache::InfraCache;
44
use crate::schema::SwitchCache;
5-
use crate::schema::TrackEndpoint;
65
use editoast_common::Identifier;
6+
use editoast_schemas::infra::TrackEndpoint;
77

88
#[derive(Default, Clone, Debug)]
99
pub struct Graph<'a> {
@@ -92,8 +92,8 @@ mod tests {
9292
use crate::infra_cache::tests::create_small_infra_cache;
9393
use crate::infra_cache::tests::create_track_endpoint;
9494
use crate::infra_cache::InfraCache;
95-
use crate::schema::Endpoint;
9695
use editoast_common::Identifier;
96+
use editoast_schemas::infra::Endpoint;
9797

9898
#[test]
9999
fn create_empty_graph() {

editoast/src/infra_cache/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -751,19 +751,19 @@ pub mod tests {
751751
use crate::modelsv2::infra::tests::test_infra_transaction;
752752
use crate::schema::ApplicableDirectionsTrackRange;
753753
use crate::schema::Electrification;
754-
use crate::schema::Endpoint;
755754
use crate::schema::OperationalPoint;
756755
use crate::schema::OperationalPointPartCache;
757756
use crate::schema::Route;
758757
use crate::schema::SpeedSection;
759758
use crate::schema::Switch;
760759
use crate::schema::SwitchPortConnection;
761760
use crate::schema::SwitchType;
762-
use crate::schema::TrackEndpoint;
763761
use editoast_common::Identifier;
764762
use editoast_common::NonBlankString;
765763
use editoast_schemas::infra::ApplicableDirections;
766764
use editoast_schemas::infra::Direction;
765+
use editoast_schemas::infra::Endpoint;
766+
use editoast_schemas::infra::TrackEndpoint;
767767
use editoast_schemas::primitives::OSRDIdentified;
768768

769769
#[actix_test]
@@ -1287,9 +1287,9 @@ pub mod tests {
12871287
use crate::infra_cache::tests::create_switch_type_cache;
12881288
use crate::infra_cache::InfraCache;
12891289
use crate::infra_cache::InfraCacheEditoastError;
1290-
use crate::schema::TrackEndpoint;
12911290
use editoast_common::Identifier;
12921291
use editoast_schemas::infra::Direction::StartToStop;
1292+
use editoast_schemas::infra::TrackEndpoint;
12931293
use editoast_schemas::infra::Waypoint::BufferStop;
12941294
use editoast_schemas::primitives::ObjectType;
12951295

editoast/src/schema/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use serde::Deserialize;
33
use serde::Serialize;
44
use strum::VariantNames;
55

6-
use super::Endpoint;
76
use super::OSRDIdentified;
87
use super::ObjectType;
8+
use editoast_schemas::infra::Endpoint;
99
use editoast_schemas::primitives::ObjectRef;
1010

1111
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]

editoast/src/schema/mod.rs

-40
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub use buffer_stop::BufferStopCache;
2020
pub use detector::Detector;
2121
pub use detector::DetectorCache;
2222
use editoast_schemas::infra::ApplicableDirections;
23-
use editoast_schemas::infra::Direction;
2423
use editoast_schemas::primitives::OSRDIdentified;
2524
use editoast_schemas::primitives::ObjectType;
2625
pub use electrification::Electrification;
@@ -103,42 +102,3 @@ impl ApplicableDirectionsTrackRange {
103102
}
104103
}
105104
}
106-
107-
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash)]
108-
#[serde(rename_all = "UPPERCASE")]
109-
pub enum Endpoint {
110-
Begin,
111-
End,
112-
}
113-
114-
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
115-
#[derivative(Default)]
116-
#[serde(deny_unknown_fields)]
117-
pub struct TrackEndpoint {
118-
#[derivative(Default(value = "Endpoint::Begin"))]
119-
pub endpoint: Endpoint,
120-
#[derivative(Default(value = r#""InvalidRef".into()"#))]
121-
pub track: Identifier,
122-
}
123-
124-
impl TrackEndpoint {
125-
/// Create a new `TrackEndpoint` from a track id and an endpoint.
126-
pub fn new<T: AsRef<str>>(track: T, endpoint: Endpoint) -> Self {
127-
TrackEndpoint {
128-
track: track.as_ref().into(),
129-
endpoint,
130-
}
131-
}
132-
133-
/// Create a `TrackEndpoint` from a track id and a direction.
134-
pub fn from_track_and_direction<T: AsRef<str>>(track: T, dir: Direction) -> TrackEndpoint {
135-
let endpoint = match dir {
136-
Direction::StartToStop => Endpoint::End,
137-
Direction::StopToStart => Endpoint::Begin,
138-
};
139-
TrackEndpoint {
140-
track: track.as_ref().into(),
141-
endpoint,
142-
}
143-
}
144-
}

editoast/src/schema/route.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ use derivative::Derivative;
44
use serde::Deserialize;
55
use serde::Serialize;
66

7-
use super::Endpoint;
87
use super::OSRDIdentified;
98
use super::ObjectType;
10-
use super::TrackEndpoint;
119
use crate::infra_cache::Cache;
1210
use crate::infra_cache::Graph;
1311
use crate::infra_cache::InfraCache;
1412
use crate::infra_cache::ObjectCache;
1513
use editoast_common::Identifier;
1614
use editoast_schemas::infra::Direction;
1715
use editoast_schemas::infra::DirectionalTrackRange;
16+
use editoast_schemas::infra::Endpoint;
17+
use editoast_schemas::infra::TrackEndpoint;
1818
use editoast_schemas::infra::Waypoint;
1919
use editoast_schemas::primitives::OSRDTyped;
2020

editoast/src/schema/switch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use serde::Serialize;
66

77
use super::OSRDIdentified;
88
use super::ObjectType;
9-
use super::TrackEndpoint;
109
use crate::infra_cache::Cache;
1110
use crate::infra_cache::ObjectCache;
1211
use editoast_common::Identifier;
1312
use editoast_common::NonBlankString;
13+
use editoast_schemas::infra::TrackEndpoint;
1414
use editoast_schemas::primitives::OSRDTyped;
1515

1616
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]

editoast/src/schema/track_section.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use geos::geojson::Value::LineString;
55
use serde::Deserialize;
66
use serde::Serialize;
77

8-
use super::Endpoint;
98
use super::OSRDIdentified;
109
use super::ObjectType;
11-
use super::TrackEndpoint;
1210
use crate::infra_cache::Cache;
1311
use crate::infra_cache::ObjectCache;
1412
use crate::map::BoundingBox;
1513
use editoast_common::Identifier;
1614
use editoast_common::NonBlankString;
15+
use editoast_schemas::infra::Endpoint;
16+
use editoast_schemas::infra::TrackEndpoint;
1717
use editoast_schemas::primitives::OSRDTyped;
1818

1919
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]

editoast/src/views/infra/auto_fixes/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ mod tests {
340340
use crate::schema::Detector;
341341
use crate::schema::DetectorCache;
342342
use crate::schema::Electrification;
343-
use crate::schema::Endpoint;
344343
use crate::schema::OperationalPoint;
345344
use crate::schema::OperationalPointPart;
346345
use crate::schema::Route;
@@ -349,11 +348,12 @@ mod tests {
349348
use crate::schema::Slope;
350349
use crate::schema::SpeedSection;
351350
use crate::schema::Switch;
352-
use crate::schema::TrackEndpoint;
353351
use crate::schema::TrackSection;
354352
use crate::views::pagination::PaginatedResponse;
355353
use crate::views::tests::create_test_service;
356354
use editoast_common::Identifier;
355+
use editoast_schemas::infra::Endpoint;
356+
use editoast_schemas::infra::TrackEndpoint;
357357
use editoast_schemas::infra::Waypoint;
358358
use editoast_schemas::primitives::ObjectRef;
359359
use editoast_schemas::primitives::ObjectType;

editoast/src/views/infra/auto_fixes/track_section.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use super::new_ref_fix_create_pair;
77
use super::Fix;
88
use crate::infra_cache::operation::RailjsonObject;
99
use crate::schema::BufferStop;
10-
use crate::schema::Endpoint;
1110
use crate::schema::InfraError;
1211
use crate::schema::InfraErrorType;
1312
use crate::schema::TrackSectionCache;
1413
use editoast_common::Identifier;
14+
use editoast_schemas::infra::Endpoint;
1515
use editoast_schemas::primitives::OSRDIdentified as _;
1616
use editoast_schemas::primitives::OSRDObject as _;
1717
use editoast_schemas::primitives::ObjectRef;

editoast/src/views/infra/pathfinding.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use crate::infra_cache::Graph;
2020
use crate::infra_cache::InfraCache;
2121
use crate::modelsv2::prelude::*;
2222
use crate::modelsv2::Infra;
23-
use crate::schema::Endpoint;
24-
use crate::schema::TrackEndpoint;
2523
use crate::views::infra::InfraApiError;
2624
use crate::views::infra::InfraIdParam;
2725
use crate::DbPool;
2826
use editoast_common::Identifier;
2927
use editoast_schemas::infra::Direction;
3028
use editoast_schemas::infra::DirectionalTrackRange;
29+
use editoast_schemas::infra::Endpoint;
30+
use editoast_schemas::infra::TrackEndpoint;
3131
use editoast_schemas::primitives::ObjectType;
3232

3333
crate::routes! {

0 commit comments

Comments
 (0)