Skip to content

Commit 102af2c

Browse files
committed
editoast: move waypoint to editoast_schemas
1 parent a8c1f11 commit 102af2c

File tree

9 files changed

+76
-68
lines changed

9 files changed

+76
-68
lines changed

editoast/editoast_schemas/src/infra.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
mod direction;
22
mod track_offset;
3+
mod waypoint;
34

45
pub use direction::Direction;
5-
66
pub use track_offset::TrackOffset;
7+
pub use waypoint::Waypoint;
78

89
editoast_common::schemas! {
910
track_offset::schemas(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use editoast_common::Identifier;
2+
use serde::Deserialize;
3+
use serde::Serialize;
4+
5+
use crate::primitives::OSRDIdentified;
6+
use crate::primitives::OSRDObject;
7+
use crate::primitives::ObjectType;
8+
9+
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash)]
10+
#[serde(tag = "type", deny_unknown_fields)]
11+
pub enum Waypoint {
12+
BufferStop { id: Identifier },
13+
Detector { id: Identifier },
14+
}
15+
16+
impl Waypoint {
17+
/// Create a new detector stop waypoint
18+
pub fn new_detector<T: AsRef<str>>(detector: T) -> Self {
19+
Self::Detector {
20+
id: detector.as_ref().into(),
21+
}
22+
}
23+
24+
/// Create a new buffer stop waypoint
25+
pub fn new_buffer_stop<T: AsRef<str>>(bf: T) -> Self {
26+
Self::BufferStop {
27+
id: bf.as_ref().into(),
28+
}
29+
}
30+
31+
/// Return whether the waypoint is a detector
32+
pub fn is_detector(&self) -> bool {
33+
matches!(self, Waypoint::Detector { .. })
34+
}
35+
36+
// Return whether the waypoint is a buffer stop
37+
pub fn is_buffer_stop(&self) -> bool {
38+
matches!(self, Waypoint::BufferStop { .. })
39+
}
40+
}
41+
42+
impl Default for Waypoint {
43+
fn default() -> Self {
44+
Self::Detector {
45+
id: "InvalidRef".into(),
46+
}
47+
}
48+
}
49+
50+
impl OSRDIdentified for Waypoint {
51+
fn get_id(&self) -> &String {
52+
match self {
53+
Waypoint::BufferStop { id } => id,
54+
Waypoint::Detector { id } => id,
55+
}
56+
}
57+
}
58+
59+
impl OSRDObject for Waypoint {
60+
fn get_type(&self) -> ObjectType {
61+
match self {
62+
Waypoint::BufferStop { .. } => ObjectType::BufferStop,
63+
Waypoint::Detector { .. } => ObjectType::Detector,
64+
}
65+
}
66+
}

editoast/src/converters/generate_routes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::collections::HashMap;
99
use crate::schema::*;
1010
use editoast_common::Identifier;
1111
use editoast_schemas::infra::Direction;
12+
use editoast_schemas::infra::Waypoint;
1213
use editoast_schemas::primitives::OSRDIdentified;
1314

1415
/* Part 1: type definitions */

editoast/src/generated_data/error/routes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::infra_cache::Graph;
77
use crate::infra_cache::InfraCache;
88
use crate::infra_cache::ObjectCache;
99
use crate::schema::InfraError;
10-
use crate::schema::Waypoint;
10+
use editoast_schemas::infra::Waypoint;
1111
use editoast_schemas::primitives::OSRDIdentified;
1212
use editoast_schemas::primitives::OSRDObject;
1313
use editoast_schemas::primitives::ObjectRef;
@@ -224,8 +224,8 @@ mod tests {
224224
use crate::infra_cache::tests::create_route_cache;
225225
use crate::infra_cache::tests::create_small_infra_cache;
226226
use crate::infra_cache::Graph;
227-
use crate::schema::Waypoint;
228227
use editoast_schemas::infra::Direction;
228+
use editoast_schemas::infra::Waypoint;
229229
use editoast_schemas::primitives::OSRDObject;
230230
use editoast_schemas::primitives::ObjectRef;
231231
use editoast_schemas::primitives::ObjectType;

editoast/src/infra_cache/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ pub mod tests {
728728
use actix_web::test as actix_test;
729729
use chashmap::CHashMap;
730730
use diesel_async::scoped_futures::ScopedFutureExt;
731+
use editoast_schemas::infra::Waypoint;
731732

732733
use super::BufferStopCache;
733734
use super::DetectorCache;
@@ -760,7 +761,6 @@ pub mod tests {
760761
use crate::schema::SwitchPortConnection;
761762
use crate::schema::SwitchType;
762763
use crate::schema::TrackEndpoint;
763-
use crate::schema::Waypoint;
764764
use editoast_common::Identifier;
765765
use editoast_common::NonBlankString;
766766
use editoast_schemas::infra::Direction;
@@ -1288,9 +1288,9 @@ pub mod tests {
12881288
use crate::infra_cache::InfraCache;
12891289
use crate::infra_cache::InfraCacheEditoastError;
12901290
use crate::schema::TrackEndpoint;
1291-
use crate::schema::Waypoint::BufferStop;
12921291
use editoast_common::Identifier;
12931292
use editoast_schemas::infra::Direction::StartToStop;
1293+
use editoast_schemas::infra::Waypoint::BufferStop;
12941294
use editoast_schemas::primitives::ObjectType;
12951295

12961296
#[test]

editoast/src/schema/mod.rs

-60
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub use detector::Detector;
2121
pub use detector::DetectorCache;
2222
use editoast_schemas::infra::Direction;
2323
use editoast_schemas::primitives::OSRDIdentified;
24-
use editoast_schemas::primitives::OSRDObject;
2524
use editoast_schemas::primitives::ObjectType;
2625
pub use electrification::Electrification;
2726
pub use errors::InfraError;
@@ -80,65 +79,6 @@ editoast_common::schemas! {
8079
operation::schemas(),
8180
}
8281

83-
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash)]
84-
#[serde(tag = "type", deny_unknown_fields)]
85-
pub enum Waypoint {
86-
BufferStop { id: Identifier },
87-
Detector { id: Identifier },
88-
}
89-
90-
impl Waypoint {
91-
/// Create a new detector stop waypoint
92-
pub fn new_detector<T: AsRef<str>>(detector: T) -> Self {
93-
Self::Detector {
94-
id: detector.as_ref().into(),
95-
}
96-
}
97-
98-
/// Create a new buffer stop waypoint
99-
pub fn new_buffer_stop<T: AsRef<str>>(bf: T) -> Self {
100-
Self::BufferStop {
101-
id: bf.as_ref().into(),
102-
}
103-
}
104-
105-
/// Return whether the waypoint is a detector
106-
pub fn is_detector(&self) -> bool {
107-
matches!(self, Waypoint::Detector { .. })
108-
}
109-
110-
// Return whether the waypoint is a buffer stop
111-
pub fn is_buffer_stop(&self) -> bool {
112-
matches!(self, Waypoint::BufferStop { .. })
113-
}
114-
}
115-
116-
impl Default for Waypoint {
117-
fn default() -> Self {
118-
Self::Detector {
119-
id: "InvalidRef".into(),
120-
}
121-
}
122-
}
123-
124-
impl OSRDIdentified for Waypoint {
125-
fn get_id(&self) -> &String {
126-
match self {
127-
Waypoint::BufferStop { id } => id,
128-
Waypoint::Detector { id } => id,
129-
}
130-
}
131-
}
132-
133-
impl OSRDObject for Waypoint {
134-
fn get_type(&self) -> ObjectType {
135-
match self {
136-
Waypoint::BufferStop { .. } => ObjectType::BufferStop,
137-
Waypoint::Detector { .. } => ObjectType::Detector,
138-
}
139-
}
140-
}
141-
14282
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
14383
#[serde(deny_unknown_fields)]
14484
#[derivative(Default)]

editoast/src/schema/route.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use super::Endpoint;
99
use super::OSRDIdentified;
1010
use super::ObjectType;
1111
use super::TrackEndpoint;
12-
use super::Waypoint;
1312
use crate::infra_cache::Cache;
1413
use crate::infra_cache::Graph;
1514
use crate::infra_cache::InfraCache;
1615
use crate::infra_cache::ObjectCache;
1716
use editoast_common::Identifier;
1817
use editoast_schemas::infra::Direction;
18+
use editoast_schemas::infra::Waypoint;
1919
use editoast_schemas::primitives::OSRDTyped;
2020

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ mod tests {
351351
use crate::schema::Switch;
352352
use crate::schema::TrackEndpoint;
353353
use crate::schema::TrackSection;
354-
use crate::schema::Waypoint;
355354
use crate::views::pagination::PaginatedResponse;
356355
use crate::views::tests::create_test_service;
357356
use editoast_common::Identifier;
357+
use editoast_schemas::infra::Waypoint;
358358
use editoast_schemas::primitives::ObjectRef;
359359
use editoast_schemas::primitives::ObjectType;
360360

editoast/src/views/infra/routes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ mod tests {
241241
use crate::schema::Detector;
242242
use crate::schema::Route;
243243
use crate::schema::TrackSection;
244-
use crate::schema::Waypoint;
245244
use crate::views::infra::routes::RoutesResponse;
246245
use crate::views::infra::routes::WaypointType;
247246
use crate::views::tests::create_test_service;
247+
use editoast_schemas::infra::Waypoint;
248248

249249
#[rstest]
250250
async fn get_routes_nodes() {

0 commit comments

Comments
 (0)