From 0b3cfb29f8f56e8eac54cdb9aee37de12fe7e02e Mon Sep 17 00:00:00 2001 From: hamz2a Date: Fri, 12 Apr 2024 17:15:04 +0200 Subject: [PATCH] editoast: move Endpoint and TrackEndpoint to editoast_schemas --- editoast/editoast_schemas/src/infra.rs | 4 ++ .../editoast_schemas/src/infra/endpoint.rs | 9 +++++ .../src/infra/track_endpoint.rs | 39 ++++++++++++++++++ editoast/src/converters/generate_routes.rs | 2 + editoast/src/converters/osm_to_railjson.rs | 4 +- editoast/src/converters/utils.rs | 2 + .../src/generated_data/error/buffer_stops.rs | 6 +-- editoast/src/generated_data/error/switches.rs | 4 +- editoast/src/infra_cache/graph.rs | 4 +- editoast/src/infra_cache/mod.rs | 6 +-- editoast/src/schema/errors.rs | 2 +- editoast/src/schema/mod.rs | 40 ------------------- editoast/src/schema/route.rs | 4 +- editoast/src/schema/switch.rs | 2 +- editoast/src/schema/track_section.rs | 4 +- editoast/src/views/infra/auto_fixes/mod.rs | 4 +- .../views/infra/auto_fixes/track_section.rs | 2 +- editoast/src/views/infra/pathfinding.rs | 4 +- 18 files changed, 80 insertions(+), 62 deletions(-) create mode 100644 editoast/editoast_schemas/src/infra/endpoint.rs create mode 100644 editoast/editoast_schemas/src/infra/track_endpoint.rs diff --git a/editoast/editoast_schemas/src/infra.rs b/editoast/editoast_schemas/src/infra.rs index 44ef885837f..c69fdaa36ee 100644 --- a/editoast/editoast_schemas/src/infra.rs +++ b/editoast/editoast_schemas/src/infra.rs @@ -1,8 +1,10 @@ mod applicable_directions; mod direction; mod directional_track_range; +mod endpoint; mod side; mod sign; +mod track_endpoint; mod track_location; mod track_offset; mod track_range; @@ -11,8 +13,10 @@ mod waypoint; pub use applicable_directions::ApplicableDirections; pub use direction::Direction; pub use directional_track_range::DirectionalTrackRange; +pub use endpoint::Endpoint; pub use side::Side; pub use sign::Sign; +pub use track_endpoint::TrackEndpoint; pub use track_location::TrackLocation; pub use track_offset::TrackOffset; pub use track_range::TrackRange; diff --git a/editoast/editoast_schemas/src/infra/endpoint.rs b/editoast/editoast_schemas/src/infra/endpoint.rs new file mode 100644 index 00000000000..2a6623e23f1 --- /dev/null +++ b/editoast/editoast_schemas/src/infra/endpoint.rs @@ -0,0 +1,9 @@ +use serde::Deserialize; +use serde::Serialize; + +#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash)] +#[serde(rename_all = "UPPERCASE")] +pub enum Endpoint { + Begin, + End, +} diff --git a/editoast/editoast_schemas/src/infra/track_endpoint.rs b/editoast/editoast_schemas/src/infra/track_endpoint.rs new file mode 100644 index 00000000000..bcf00817d36 --- /dev/null +++ b/editoast/editoast_schemas/src/infra/track_endpoint.rs @@ -0,0 +1,39 @@ +use derivative::Derivative; +use editoast_common::Identifier; +use serde::Deserialize; +use serde::Serialize; + +use super::Direction; +use super::Endpoint; + +#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)] +#[derivative(Default)] +#[serde(deny_unknown_fields)] +pub struct TrackEndpoint { + #[derivative(Default(value = "Endpoint::Begin"))] + pub endpoint: Endpoint, + #[derivative(Default(value = r#""InvalidRef".into()"#))] + pub track: Identifier, +} + +impl TrackEndpoint { + /// Create a new `TrackEndpoint` from a track id and an endpoint. + pub fn new>(track: T, endpoint: Endpoint) -> Self { + TrackEndpoint { + track: track.as_ref().into(), + endpoint, + } + } + + /// Create a `TrackEndpoint` from a track id and a direction. + pub fn from_track_and_direction>(track: T, dir: Direction) -> TrackEndpoint { + let endpoint = match dir { + Direction::StartToStop => Endpoint::End, + Direction::StopToStart => Endpoint::Begin, + }; + TrackEndpoint { + track: track.as_ref().into(), + endpoint, + } + } +} diff --git a/editoast/src/converters/generate_routes.rs b/editoast/src/converters/generate_routes.rs index d30047418ec..4319c728fd3 100644 --- a/editoast/src/converters/generate_routes.rs +++ b/editoast/src/converters/generate_routes.rs @@ -9,6 +9,8 @@ use std::collections::HashMap; use crate::schema::*; use editoast_common::Identifier; use editoast_schemas::infra::Direction; +use editoast_schemas::infra::Endpoint; +use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::infra::Waypoint; use editoast_schemas::primitives::OSRDIdentified; diff --git a/editoast/src/converters/osm_to_railjson.rs b/editoast/src/converters/osm_to_railjson.rs index dd8be13b895..486c801d374 100644 --- a/editoast/src/converters/osm_to_railjson.rs +++ b/editoast/src/converters/osm_to_railjson.rs @@ -127,13 +127,15 @@ pub fn parse_osm(osm_pbf_in: PathBuf) -> Result { @@ -92,8 +92,8 @@ mod tests { use crate::infra_cache::tests::create_small_infra_cache; use crate::infra_cache::tests::create_track_endpoint; use crate::infra_cache::InfraCache; - use crate::schema::Endpoint; use editoast_common::Identifier; + use editoast_schemas::infra::Endpoint; #[test] fn create_empty_graph() { diff --git a/editoast/src/infra_cache/mod.rs b/editoast/src/infra_cache/mod.rs index 22bde327195..8995f65f71c 100644 --- a/editoast/src/infra_cache/mod.rs +++ b/editoast/src/infra_cache/mod.rs @@ -751,7 +751,6 @@ pub mod tests { use crate::modelsv2::infra::tests::test_infra_transaction; use crate::schema::ApplicableDirectionsTrackRange; use crate::schema::Electrification; - use crate::schema::Endpoint; use crate::schema::OperationalPoint; use crate::schema::OperationalPointPartCache; use crate::schema::Route; @@ -759,11 +758,12 @@ pub mod tests { use crate::schema::Switch; use crate::schema::SwitchPortConnection; use crate::schema::SwitchType; - use crate::schema::TrackEndpoint; use editoast_common::Identifier; use editoast_common::NonBlankString; use editoast_schemas::infra::ApplicableDirections; use editoast_schemas::infra::Direction; + use editoast_schemas::infra::Endpoint; + use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::primitives::OSRDIdentified; #[actix_test] @@ -1287,9 +1287,9 @@ pub mod tests { use crate::infra_cache::tests::create_switch_type_cache; use crate::infra_cache::InfraCache; use crate::infra_cache::InfraCacheEditoastError; - use crate::schema::TrackEndpoint; use editoast_common::Identifier; use editoast_schemas::infra::Direction::StartToStop; + use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::infra::Waypoint::BufferStop; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/schema/errors.rs b/editoast/src/schema/errors.rs index 51023d1b42f..93db0fe6f91 100644 --- a/editoast/src/schema/errors.rs +++ b/editoast/src/schema/errors.rs @@ -3,9 +3,9 @@ use serde::Deserialize; use serde::Serialize; use strum::VariantNames; -use super::Endpoint; use super::OSRDIdentified; use super::ObjectType; +use editoast_schemas::infra::Endpoint; use editoast_schemas::primitives::ObjectRef; #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] diff --git a/editoast/src/schema/mod.rs b/editoast/src/schema/mod.rs index c192c3ab466..deb71c7593e 100644 --- a/editoast/src/schema/mod.rs +++ b/editoast/src/schema/mod.rs @@ -20,7 +20,6 @@ pub use buffer_stop::BufferStopCache; pub use detector::Detector; pub use detector::DetectorCache; use editoast_schemas::infra::ApplicableDirections; -use editoast_schemas::infra::Direction; use editoast_schemas::primitives::OSRDIdentified; use editoast_schemas::primitives::ObjectType; pub use electrification::Electrification; @@ -103,42 +102,3 @@ impl ApplicableDirectionsTrackRange { } } } - -#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash)] -#[serde(rename_all = "UPPERCASE")] -pub enum Endpoint { - Begin, - End, -} - -#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)] -#[derivative(Default)] -#[serde(deny_unknown_fields)] -pub struct TrackEndpoint { - #[derivative(Default(value = "Endpoint::Begin"))] - pub endpoint: Endpoint, - #[derivative(Default(value = r#""InvalidRef".into()"#))] - pub track: Identifier, -} - -impl TrackEndpoint { - /// Create a new `TrackEndpoint` from a track id and an endpoint. - pub fn new>(track: T, endpoint: Endpoint) -> Self { - TrackEndpoint { - track: track.as_ref().into(), - endpoint, - } - } - - /// Create a `TrackEndpoint` from a track id and a direction. - pub fn from_track_and_direction>(track: T, dir: Direction) -> TrackEndpoint { - let endpoint = match dir { - Direction::StartToStop => Endpoint::End, - Direction::StopToStart => Endpoint::Begin, - }; - TrackEndpoint { - track: track.as_ref().into(), - endpoint, - } - } -} diff --git a/editoast/src/schema/route.rs b/editoast/src/schema/route.rs index 2374d9bbab6..76e1d6d7d7e 100644 --- a/editoast/src/schema/route.rs +++ b/editoast/src/schema/route.rs @@ -4,10 +4,8 @@ use derivative::Derivative; use serde::Deserialize; use serde::Serialize; -use super::Endpoint; use super::OSRDIdentified; use super::ObjectType; -use super::TrackEndpoint; use crate::infra_cache::Cache; use crate::infra_cache::Graph; use crate::infra_cache::InfraCache; @@ -15,6 +13,8 @@ use crate::infra_cache::ObjectCache; use editoast_common::Identifier; use editoast_schemas::infra::Direction; use editoast_schemas::infra::DirectionalTrackRange; +use editoast_schemas::infra::Endpoint; +use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::infra::Waypoint; use editoast_schemas::primitives::OSRDTyped; diff --git a/editoast/src/schema/switch.rs b/editoast/src/schema/switch.rs index ebbb53b6f32..be72d6a1740 100644 --- a/editoast/src/schema/switch.rs +++ b/editoast/src/schema/switch.rs @@ -6,11 +6,11 @@ use serde::Serialize; use super::OSRDIdentified; use super::ObjectType; -use super::TrackEndpoint; use crate::infra_cache::Cache; use crate::infra_cache::ObjectCache; use editoast_common::Identifier; use editoast_common::NonBlankString; +use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::primitives::OSRDTyped; #[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)] diff --git a/editoast/src/schema/track_section.rs b/editoast/src/schema/track_section.rs index 1563a1a8177..ffd1ddb1e43 100644 --- a/editoast/src/schema/track_section.rs +++ b/editoast/src/schema/track_section.rs @@ -5,15 +5,15 @@ use geos::geojson::Value::LineString; use serde::Deserialize; use serde::Serialize; -use super::Endpoint; use super::OSRDIdentified; use super::ObjectType; -use super::TrackEndpoint; use crate::infra_cache::Cache; use crate::infra_cache::ObjectCache; use crate::map::BoundingBox; use editoast_common::Identifier; use editoast_common::NonBlankString; +use editoast_schemas::infra::Endpoint; +use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::primitives::OSRDTyped; #[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)] diff --git a/editoast/src/views/infra/auto_fixes/mod.rs b/editoast/src/views/infra/auto_fixes/mod.rs index 8e681bd2e0a..06e087d9a36 100644 --- a/editoast/src/views/infra/auto_fixes/mod.rs +++ b/editoast/src/views/infra/auto_fixes/mod.rs @@ -340,7 +340,6 @@ mod tests { use crate::schema::Detector; use crate::schema::DetectorCache; use crate::schema::Electrification; - use crate::schema::Endpoint; use crate::schema::OperationalPoint; use crate::schema::OperationalPointPart; use crate::schema::Route; @@ -349,11 +348,12 @@ mod tests { use crate::schema::Slope; use crate::schema::SpeedSection; use crate::schema::Switch; - use crate::schema::TrackEndpoint; use crate::schema::TrackSection; use crate::views::pagination::PaginatedResponse; use crate::views::tests::create_test_service; use editoast_common::Identifier; + use editoast_schemas::infra::Endpoint; + use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::infra::Waypoint; use editoast_schemas::primitives::ObjectRef; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/views/infra/auto_fixes/track_section.rs b/editoast/src/views/infra/auto_fixes/track_section.rs index b02f9b7a34f..1bf77ee9477 100644 --- a/editoast/src/views/infra/auto_fixes/track_section.rs +++ b/editoast/src/views/infra/auto_fixes/track_section.rs @@ -7,11 +7,11 @@ use super::new_ref_fix_create_pair; use super::Fix; use crate::infra_cache::operation::RailjsonObject; use crate::schema::BufferStop; -use crate::schema::Endpoint; use crate::schema::InfraError; use crate::schema::InfraErrorType; use crate::schema::TrackSectionCache; use editoast_common::Identifier; +use editoast_schemas::infra::Endpoint; use editoast_schemas::primitives::OSRDIdentified as _; use editoast_schemas::primitives::OSRDObject as _; use editoast_schemas::primitives::ObjectRef; diff --git a/editoast/src/views/infra/pathfinding.rs b/editoast/src/views/infra/pathfinding.rs index b348968aadd..92637ebf500 100644 --- a/editoast/src/views/infra/pathfinding.rs +++ b/editoast/src/views/infra/pathfinding.rs @@ -20,14 +20,14 @@ use crate::infra_cache::Graph; use crate::infra_cache::InfraCache; use crate::modelsv2::prelude::*; use crate::modelsv2::Infra; -use crate::schema::Endpoint; -use crate::schema::TrackEndpoint; use crate::views::infra::InfraApiError; use crate::views::infra::InfraIdParam; use crate::DbPool; use editoast_common::Identifier; use editoast_schemas::infra::Direction; use editoast_schemas::infra::DirectionalTrackRange; +use editoast_schemas::infra::Endpoint; +use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::primitives::ObjectType; crate::routes! {