From 161ff6a491783e878973f82f594444eb00e0ecda Mon Sep 17 00:00:00 2001 From: hamz2a Date: Tue, 23 Apr 2024 10:27:58 +0200 Subject: [PATCH 1/7] editoast: create bouding_box.rs in primitives folder --- editoast/editoast_schemas/src/primitives.rs | 142 +---------------- .../src/primitives/bounding_box.rs | 143 ++++++++++++++++++ 2 files changed, 148 insertions(+), 137 deletions(-) create mode 100644 editoast/editoast_schemas/src/primitives/bounding_box.rs diff --git a/editoast/editoast_schemas/src/primitives.rs b/editoast/editoast_schemas/src/primitives.rs index 36b58b07648..0d1181c110f 100644 --- a/editoast/editoast_schemas/src/primitives.rs +++ b/editoast/editoast_schemas/src/primitives.rs @@ -1,21 +1,19 @@ +mod bounding_box; + +pub use bounding_box::BoundingBox; + use derivative::Derivative; use enum_map::Enum; -use geojson; -use geojson::Geometry; -use geojson::Value::LineString; use serde::Deserialize; use serde::Serialize; -use std::iter::FromIterator; use strum::Display; use strum::EnumIter; use utoipa::ToSchema; -use crate::errors::GeometryError; - editoast_common::schemas! { ObjectType, Zone, - BoundingBox, + bounding_box::schemas(), } /// This trait should be implemented by all struct that represents an OSRD type. @@ -90,107 +88,6 @@ impl ObjectRef { } } -/// A bounding box -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ToSchema)] -pub struct BoundingBox(pub (f64, f64), pub (f64, f64)); - -impl FromIterator<(f64, f64)> for BoundingBox { - fn from_iter>(iter: I) -> Self { - let mut min: (f64, f64) = (f64::MAX, f64::MAX); - let mut max: (f64, f64) = (f64::MIN, f64::MIN); - - for (x, y) in iter { - min.0 = min.0.min(x); - max.0 = max.0.max(x); - min.1 = min.1.min(y); - max.1 = max.1.max(y); - } - - BoundingBox(min, max) - } -} - -impl BoundingBox { - pub fn union(&mut self, b: &Self) -> &mut Self { - self.0 = (self.0 .0.min(b.0 .0), self.0 .1.min(b.0 .1)); - self.1 = (self.1 .0.max(b.1 .0), self.1 .1.max(b.1 .1)); - self - } - - pub fn is_valid(&self) -> bool { - self.0 .0 <= self.1 .0 && self.0 .1 <= self.1 .1 - } - - pub fn from_geojson(value: geojson::Value) -> Result { - match value { - LineString(segments) => Ok(Self::from_iter(segments.into_iter().map(|points| { - ( - *points.first().expect("invalid point"), - *points.get(1).expect("invalid point"), - ) - }))), - value => Err(GeometryError::UnexpectedGeometry { - expected: "LineString".to_owned(), - actual: value.to_string(), - }), - } - } - - pub fn from_geometry(value: Geometry) -> Result { - Self::from_geojson(value.value) - } - - /// Calculates the diagonal length of the bounding box using the Haversine formula. - /// - /// # Returns - /// - /// * `f64` - The diagonal length of the bounding box in meters. - /// - /// # Examples - /// - /// ``` - /// use editoast_schemas::primitives::BoundingBox; - /// - /// let bbox = BoundingBox((40.0, -75.0), (42.0, -73.0)); - /// let diagonal_length = bbox.diagonal_length(); - /// assert_eq!(diagonal_length, 230908.62753622115); - /// ``` - pub fn diagonal_length(&self) -> f64 { - // Earth's mean radius in meters - let r: f64 = 6_378_100.0; - - let a_lon = self.0 .0; - let a_lat = self.0 .1; - let b_lon = self.1 .0; - let b_lat = self.1 .1; - - // Calculate differences in longitude and latitude in radians - let d_lon: f64 = (b_lon - a_lon).to_radians(); - let d_lat: f64 = (b_lat - a_lat).to_radians(); - - // Convert latitude to radians - let lat1: f64 = a_lat.to_radians(); - let lat2: f64 = b_lat.to_radians(); - - // Haversine formula - let a: f64 = ((d_lat / 2.0).sin()) * ((d_lat / 2.0).sin()) - + ((d_lon / 2.0).sin()) * ((d_lon / 2.0).sin()) * (lat1.cos()) * (lat2.cos()); - let c: f64 = 2.0 * ((a.sqrt()).atan2((1.0 - a).sqrt())); - - // Calculate diagonal length - r * c - } -} - -impl Default for BoundingBox { - fn default() -> Self { - Self( - (f64::INFINITY, f64::INFINITY), - (f64::NEG_INFINITY, f64::NEG_INFINITY), - ) - } -} - /// Geographic and Schematic bounding box zone impacted by a list of operations. /// Zones use the coordinate system [epsg:4326](https://epsg.io/4326). #[derive(Debug, Clone, Default, Serialize, ToSchema)] @@ -205,32 +102,3 @@ impl Zone { self.sch.union(&other.sch); } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_bounding_box_union() { - let mut a = BoundingBox((0., 0.), (1., 1.)); - let b = BoundingBox((2., 2.), (3., 3.)); - a.union(&b); - assert_eq!(a, BoundingBox((0., 0.), (3., 3.))); - } - - #[test] - fn test_bounding_box_min() { - let mut min = BoundingBox::default(); - let a = BoundingBox((0., 0.), (1., 1.)); - min.union(&a); - assert_eq!(min, a); - } - - #[test] - fn test_validity() { - assert!(BoundingBox((0., 0.), (1., 1.)).is_valid()); - assert!(!BoundingBox((1., 0.), (0., 1.)).is_valid()); - assert!(!BoundingBox((0., 1.), (1., 0.)).is_valid()); - assert!(!BoundingBox::default().is_valid()); - } -} diff --git a/editoast/editoast_schemas/src/primitives/bounding_box.rs b/editoast/editoast_schemas/src/primitives/bounding_box.rs new file mode 100644 index 00000000000..5d909e796bd --- /dev/null +++ b/editoast/editoast_schemas/src/primitives/bounding_box.rs @@ -0,0 +1,143 @@ +use geojson; +use geojson::Geometry; +use geojson::Value::LineString; +use serde::Deserialize; +use serde::Serialize; +use std::iter::FromIterator; +use utoipa::ToSchema; + +use crate::errors::GeometryError; + +editoast_common::schemas! { + BoundingBox, +} + +/// A bounding box +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ToSchema)] +pub struct BoundingBox(pub (f64, f64), pub (f64, f64)); + +impl FromIterator<(f64, f64)> for BoundingBox { + fn from_iter>(iter: I) -> Self { + let mut min: (f64, f64) = (f64::MAX, f64::MAX); + let mut max: (f64, f64) = (f64::MIN, f64::MIN); + + for (x, y) in iter { + min.0 = min.0.min(x); + max.0 = max.0.max(x); + min.1 = min.1.min(y); + max.1 = max.1.max(y); + } + + BoundingBox(min, max) + } +} + +impl BoundingBox { + pub fn union(&mut self, b: &Self) -> &mut Self { + self.0 = (self.0 .0.min(b.0 .0), self.0 .1.min(b.0 .1)); + self.1 = (self.1 .0.max(b.1 .0), self.1 .1.max(b.1 .1)); + self + } + + pub fn is_valid(&self) -> bool { + self.0 .0 <= self.1 .0 && self.0 .1 <= self.1 .1 + } + + pub fn from_geojson(value: geojson::Value) -> Result { + match value { + LineString(segments) => Ok(Self::from_iter(segments.into_iter().map(|points| { + ( + *points.first().expect("invalid point"), + *points.get(1).expect("invalid point"), + ) + }))), + value => Err(GeometryError::UnexpectedGeometry { + expected: "LineString".to_owned(), + actual: value.to_string(), + }), + } + } + + pub fn from_geometry(value: Geometry) -> Result { + Self::from_geojson(value.value) + } + + /// Calculates the diagonal length of the bounding box using the Haversine formula. + /// + /// # Returns + /// + /// * `f64` - The diagonal length of the bounding box in meters. + /// + /// # Examples + /// + /// ``` + /// use editoast_schemas::primitives::BoundingBox; + /// + /// let bbox = BoundingBox((40.0, -75.0), (42.0, -73.0)); + /// let diagonal_length = bbox.diagonal_length(); + /// assert_eq!(diagonal_length, 230908.62753622115); + /// ``` + pub fn diagonal_length(&self) -> f64 { + // Earth's mean radius in meters + let r: f64 = 6_378_100.0; + + let a_lon = self.0 .0; + let a_lat = self.0 .1; + let b_lon = self.1 .0; + let b_lat = self.1 .1; + + // Calculate differences in longitude and latitude in radians + let d_lon: f64 = (b_lon - a_lon).to_radians(); + let d_lat: f64 = (b_lat - a_lat).to_radians(); + + // Convert latitude to radians + let lat1: f64 = a_lat.to_radians(); + let lat2: f64 = b_lat.to_radians(); + + // Haversine formula + let a: f64 = ((d_lat / 2.0).sin()) * ((d_lat / 2.0).sin()) + + ((d_lon / 2.0).sin()) * ((d_lon / 2.0).sin()) * (lat1.cos()) * (lat2.cos()); + let c: f64 = 2.0 * ((a.sqrt()).atan2((1.0 - a).sqrt())); + + // Calculate diagonal length + r * c + } +} + +impl Default for BoundingBox { + fn default() -> Self { + Self( + (f64::INFINITY, f64::INFINITY), + (f64::NEG_INFINITY, f64::NEG_INFINITY), + ) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_bounding_box_union() { + let mut a = BoundingBox((0., 0.), (1., 1.)); + let b = BoundingBox((2., 2.), (3., 3.)); + a.union(&b); + assert_eq!(a, BoundingBox((0., 0.), (3., 3.))); + } + + #[test] + fn test_bounding_box_min() { + let mut min = BoundingBox::default(); + let a = BoundingBox((0., 0.), (1., 1.)); + min.union(&a); + assert_eq!(min, a); + } + + #[test] + fn test_validity() { + assert!(BoundingBox((0., 0.), (1., 1.)).is_valid()); + assert!(!BoundingBox((1., 0.), (0., 1.)).is_valid()); + assert!(!BoundingBox((0., 1.), (1., 0.)).is_valid()); + assert!(!BoundingBox::default().is_valid()); + } +} From 3b20aa2e004f4403c1a3b96e861c040100662112 Mon Sep 17 00:00:00 2001 From: hamz2a Date: Tue, 23 Apr 2024 10:34:40 +0200 Subject: [PATCH 2/7] editoast: create zone.rs in primitives folder --- editoast/editoast_schemas/src/primitives.rs | 19 +++------------ .../editoast_schemas/src/primitives/zone.rs | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 editoast/editoast_schemas/src/primitives/zone.rs diff --git a/editoast/editoast_schemas/src/primitives.rs b/editoast/editoast_schemas/src/primitives.rs index 0d1181c110f..bd7d65794d2 100644 --- a/editoast/editoast_schemas/src/primitives.rs +++ b/editoast/editoast_schemas/src/primitives.rs @@ -1,6 +1,8 @@ mod bounding_box; +mod zone; pub use bounding_box::BoundingBox; +pub use zone::Zone; use derivative::Derivative; use enum_map::Enum; @@ -12,7 +14,7 @@ use utoipa::ToSchema; editoast_common::schemas! { ObjectType, - Zone, + zone::schemas(), bounding_box::schemas(), } @@ -87,18 +89,3 @@ impl ObjectRef { ObjectRef { obj_type, obj_id } } } - -/// Geographic and Schematic bounding box zone impacted by a list of operations. -/// Zones use the coordinate system [epsg:4326](https://epsg.io/4326). -#[derive(Debug, Clone, Default, Serialize, ToSchema)] -pub struct Zone { - pub geo: BoundingBox, - pub sch: BoundingBox, -} - -impl Zone { - pub fn union(&mut self, other: &Self) { - self.geo.union(&other.geo); - self.sch.union(&other.sch); - } -} diff --git a/editoast/editoast_schemas/src/primitives/zone.rs b/editoast/editoast_schemas/src/primitives/zone.rs new file mode 100644 index 00000000000..beb4aad05d4 --- /dev/null +++ b/editoast/editoast_schemas/src/primitives/zone.rs @@ -0,0 +1,23 @@ +use serde::Serialize; +use utoipa::ToSchema; + +use super::BoundingBox; + +editoast_common::schemas! { + Zone, +} + +/// Geographic and Schematic bounding box zone impacted by a list of operations. +/// Zones use the coordinate system [epsg:4326](https://epsg.io/4326). +#[derive(Debug, Clone, Default, Serialize, ToSchema)] +pub struct Zone { + pub geo: BoundingBox, + pub sch: BoundingBox, +} + +impl Zone { + pub fn union(&mut self, other: &Self) { + self.geo.union(&other.geo); + self.sch.union(&other.sch); + } +} From 3f822e7acc9adbc3c34d44afed34afb9a4503140 Mon Sep 17 00:00:00 2001 From: hamz2a Date: Tue, 23 Apr 2024 10:40:14 +0200 Subject: [PATCH 3/7] editoast: create object_type.rs in primitives folder --- editoast/editoast_schemas/src/primitives.rs | 37 ++---------------- .../src/primitives/object_type.rs | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 editoast/editoast_schemas/src/primitives/object_type.rs diff --git a/editoast/editoast_schemas/src/primitives.rs b/editoast/editoast_schemas/src/primitives.rs index bd7d65794d2..4eaaf7270cc 100644 --- a/editoast/editoast_schemas/src/primitives.rs +++ b/editoast/editoast_schemas/src/primitives.rs @@ -1,19 +1,17 @@ mod bounding_box; mod zone; +mod object_type; pub use bounding_box::BoundingBox; pub use zone::Zone; +pub use object_type::ObjectType; use derivative::Derivative; -use enum_map::Enum; use serde::Deserialize; use serde::Serialize; -use strum::Display; -use strum::EnumIter; -use utoipa::ToSchema; editoast_common::schemas! { - ObjectType, + object_type::schemas(), zone::schemas(), bounding_box::schemas(), } @@ -43,35 +41,6 @@ impl OSRDObject for T { } } -#[derive( - Debug, - Clone, - Copy, - Deserialize, - Hash, - Eq, - PartialEq, - Serialize, - Enum, - EnumIter, - Display, - ToSchema, -)] -#[serde(deny_unknown_fields)] -pub enum ObjectType { - TrackSection, - Signal, - SpeedSection, - Detector, - NeutralSection, - Switch, - SwitchType, - BufferStop, - Route, - OperationalPoint, - Electrification, -} - #[derive(Deserialize, Derivative, Serialize, Clone, Debug, PartialEq, Eq, Hash)] #[derivative(Default)] #[serde(deny_unknown_fields)] diff --git a/editoast/editoast_schemas/src/primitives/object_type.rs b/editoast/editoast_schemas/src/primitives/object_type.rs new file mode 100644 index 00000000000..484506b5c63 --- /dev/null +++ b/editoast/editoast_schemas/src/primitives/object_type.rs @@ -0,0 +1,39 @@ +use enum_map::Enum; +use serde::Deserialize; +use serde::Serialize; +use strum::Display; +use strum::EnumIter; +use utoipa::ToSchema; + +editoast_common::schemas! { + ObjectType, +} + +#[derive( + Debug, + Clone, + Copy, + Deserialize, + Hash, + Eq, + PartialEq, + Serialize, + Enum, + EnumIter, + Display, + ToSchema, +)] +#[serde(deny_unknown_fields)] +pub enum ObjectType { + TrackSection, + Signal, + SpeedSection, + Detector, + NeutralSection, + Switch, + SwitchType, + BufferStop, + Route, + OperationalPoint, + Electrification, +} From 3851c4f88c42bf63a1fe0c5dc6cbbd966525a7f3 Mon Sep 17 00:00:00 2001 From: hamz2a Date: Tue, 23 Apr 2024 10:48:04 +0200 Subject: [PATCH 4/7] editoast: create object_ref.rs in primitives folder --- editoast/editoast_schemas/src/primitives.rs | 28 +++---------------- .../src/primitives/object_ref.rs | 23 +++++++++++++++ 2 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 editoast/editoast_schemas/src/primitives/object_ref.rs diff --git a/editoast/editoast_schemas/src/primitives.rs b/editoast/editoast_schemas/src/primitives.rs index 4eaaf7270cc..41aaf86d92e 100644 --- a/editoast/editoast_schemas/src/primitives.rs +++ b/editoast/editoast_schemas/src/primitives.rs @@ -1,14 +1,12 @@ mod bounding_box; -mod zone; +mod object_ref; mod object_type; +mod zone; pub use bounding_box::BoundingBox; -pub use zone::Zone; +pub use object_ref::ObjectRef; pub use object_type::ObjectType; - -use derivative::Derivative; -use serde::Deserialize; -use serde::Serialize; +pub use zone::Zone; editoast_common::schemas! { object_type::schemas(), @@ -40,21 +38,3 @@ impl OSRDObject for T { T::get_type() } } - -#[derive(Deserialize, Derivative, Serialize, Clone, Debug, PartialEq, Eq, Hash)] -#[derivative(Default)] -#[serde(deny_unknown_fields)] -pub struct ObjectRef { - #[serde(rename = "type")] - #[derivative(Default(value = "ObjectType::TrackSection"))] - pub obj_type: ObjectType, - #[derivative(Default(value = r#""InvalidRef".into()"#))] - pub obj_id: String, -} - -impl ObjectRef { - pub fn new>(obj_type: ObjectType, obj_id: T) -> Self { - let obj_id: String = obj_id.as_ref().to_string(); - ObjectRef { obj_type, obj_id } - } -} diff --git a/editoast/editoast_schemas/src/primitives/object_ref.rs b/editoast/editoast_schemas/src/primitives/object_ref.rs new file mode 100644 index 00000000000..1fa869cf4c1 --- /dev/null +++ b/editoast/editoast_schemas/src/primitives/object_ref.rs @@ -0,0 +1,23 @@ +use derivative::Derivative; +use serde::Deserialize; +use serde::Serialize; + +use super::ObjectType; + +#[derive(Deserialize, Derivative, Serialize, Clone, Debug, PartialEq, Eq, Hash)] +#[derivative(Default)] +#[serde(deny_unknown_fields)] +pub struct ObjectRef { + #[serde(rename = "type")] + #[derivative(Default(value = "ObjectType::TrackSection"))] + pub obj_type: ObjectType, + #[derivative(Default(value = r#""InvalidRef".into()"#))] + pub obj_id: String, +} + +impl ObjectRef { + pub fn new>(obj_type: ObjectType, obj_id: T) -> Self { + let obj_id: String = obj_id.as_ref().to_string(); + ObjectRef { obj_type, obj_id } + } +} From 779ad2d5f6cb63134175cd3f9a46b201b76c81e9 Mon Sep 17 00:00:00 2001 From: hamz2a Date: Tue, 23 Apr 2024 11:04:11 +0200 Subject: [PATCH 5/7] editoast: move Duration to editoast_schemas::primitives --- editoast/Cargo.lock | 2 +- editoast/editoast_common/Cargo.toml | 1 - editoast/editoast_common/src/lib.rs | 2 -- editoast/editoast_schemas/Cargo.toml | 1 + editoast/editoast_schemas/src/primitives.rs | 2 ++ .../src => editoast_schemas/src/primitives}/duration.rs | 6 +++--- .../editoast_schemas/src/train_schedule/schedule_item.rs | 3 ++- 7 files changed, 9 insertions(+), 8 deletions(-) rename editoast/{editoast_common/src => editoast_schemas/src/primitives}/duration.rs (96%) diff --git a/editoast/Cargo.lock b/editoast/Cargo.lock index c7d88c94d5b..4edd0eac3a9 100644 --- a/editoast/Cargo.lock +++ b/editoast/Cargo.lock @@ -1447,7 +1447,6 @@ version = "0.1.0" dependencies = [ "chrono", "geos", - "iso8601", "rand 0.8.5", "rangemap", "serde", @@ -1479,6 +1478,7 @@ dependencies = [ "editoast_common", "enum-map", "geojson", + "iso8601", "serde", "serde_derive", "serde_json", diff --git a/editoast/editoast_common/Cargo.toml b/editoast/editoast_common/Cargo.toml index 5a78ebda2c7..1f9ceb0b268 100644 --- a/editoast/editoast_common/Cargo.toml +++ b/editoast/editoast_common/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] chrono.workspace = true geos.workspace = true -iso8601 = "0.6.1" rand.workspace = true rangemap.workspace = true serde.workspace = true diff --git a/editoast/editoast_common/src/lib.rs b/editoast/editoast_common/src/lib.rs index 6cb13bb871b..8ac3b8651c8 100644 --- a/editoast/editoast_common/src/lib.rs +++ b/editoast/editoast_common/src/lib.rs @@ -1,4 +1,3 @@ -pub mod duration; pub mod geometry; mod hash_rounded_float; mod identifier; @@ -6,7 +5,6 @@ mod non_blank_string; pub mod rangemap_utils; pub mod schemas; -pub use duration::PositiveDuration; pub use hash_rounded_float::hash_float; pub use hash_rounded_float::hash_float_slice; pub use identifier::Identifier; diff --git a/editoast/editoast_schemas/Cargo.toml b/editoast/editoast_schemas/Cargo.toml index 329311c5d8f..c125404ac44 100644 --- a/editoast/editoast_schemas/Cargo.toml +++ b/editoast/editoast_schemas/Cargo.toml @@ -10,6 +10,7 @@ derivative.workspace = true editoast_common.workspace = true enum-map.workspace = true geojson.workspace = true +iso8601 = "0.6.1" serde.workspace = true serde_derive.workspace = true serde_json.workspace = true diff --git a/editoast/editoast_schemas/src/primitives.rs b/editoast/editoast_schemas/src/primitives.rs index 41aaf86d92e..4ea8bc10e86 100644 --- a/editoast/editoast_schemas/src/primitives.rs +++ b/editoast/editoast_schemas/src/primitives.rs @@ -1,9 +1,11 @@ mod bounding_box; +pub mod duration; mod object_ref; mod object_type; mod zone; pub use bounding_box::BoundingBox; +pub use duration::PositiveDuration; pub use object_ref::ObjectRef; pub use object_type::ObjectType; pub use zone::Zone; diff --git a/editoast/editoast_common/src/duration.rs b/editoast/editoast_schemas/src/primitives/duration.rs similarity index 96% rename from editoast/editoast_common/src/duration.rs rename to editoast/editoast_schemas/src/primitives/duration.rs index dfcacd4ba1f..52aad6cee2e 100644 --- a/editoast/editoast_common/src/duration.rs +++ b/editoast/editoast_schemas/src/primitives/duration.rs @@ -5,11 +5,11 @@ //! ``` //! use chrono::Duration; //! use serde::{Serialize, Deserialize}; -//! use editoast_common::duration; +//! use editoast_schemas::primitives::duration; //! //! #[derive(Serialize, Deserialize)] //! struct MyStruct { -//! #[serde(with = "editoast_common::duration")] // <- Add this line +//! #[serde(with = "editoast_schemas::primitives::duration")] // <- Add this line //! duration: Duration //! } //! @@ -42,7 +42,7 @@ pub enum PositiveDurationError { /// /// ``` /// use serde::{Serialize, Deserialize}; -/// use editoast_common::PositiveDuration; +/// use editoast_schemas::primitives::PositiveDuration; /// /// #[derive(Serialize, Deserialize)] /// struct MyStruct { diff --git a/editoast/editoast_schemas/src/train_schedule/schedule_item.rs b/editoast/editoast_schemas/src/train_schedule/schedule_item.rs index 2d1fd23877c..bf5a58f92a7 100644 --- a/editoast/editoast_schemas/src/train_schedule/schedule_item.rs +++ b/editoast/editoast_schemas/src/train_schedule/schedule_item.rs @@ -1,9 +1,10 @@ use editoast_common::NonBlankString; -use editoast_common::PositiveDuration; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; +use crate::primitives::PositiveDuration; + editoast_common::schemas! { ScheduleItem, } From 31cb9e873eaf9ff7fe6a390aa25b2ecce60848ca Mon Sep 17 00:00:00 2001 From: hamz2a Date: Tue, 23 Apr 2024 11:29:24 +0200 Subject: [PATCH 6/7] editoast: move Identifier to editoast_schemas::primitives --- editoast/Cargo.lock | 4 +++- editoast/editoast_common/Cargo.toml | 1 - editoast/editoast_common/src/lib.rs | 2 -- editoast/editoast_schemas/Cargo.toml | 3 +++ .../src/infra/applicable_directions_track_range.rs | 2 +- editoast/editoast_schemas/src/infra/buffer_stop.rs | 2 +- editoast/editoast_schemas/src/infra/detector.rs | 2 +- .../src/infra/directional_track_range.rs | 2 +- .../editoast_schemas/src/infra/electrification.rs | 2 +- .../editoast_schemas/src/infra/neutral_section.rs | 2 +- .../editoast_schemas/src/infra/operational_point.rs | 2 +- editoast/editoast_schemas/src/infra/route.rs | 2 +- editoast/editoast_schemas/src/infra/sign.rs | 2 +- editoast/editoast_schemas/src/infra/signal.rs | 2 +- editoast/editoast_schemas/src/infra/speed_section.rs | 2 +- editoast/editoast_schemas/src/infra/switch.rs | 2 +- editoast/editoast_schemas/src/infra/switch_type.rs | 2 +- editoast/editoast_schemas/src/infra/track_endpoint.rs | 2 +- editoast/editoast_schemas/src/infra/track_location.rs | 2 +- editoast/editoast_schemas/src/infra/track_offset.rs | 2 +- editoast/editoast_schemas/src/infra/track_range.rs | 2 +- editoast/editoast_schemas/src/infra/track_section.rs | 2 +- editoast/editoast_schemas/src/infra/waypoint.rs | 2 +- editoast/editoast_schemas/src/primitives.rs | 2 ++ .../src/primitives}/identifier.rs | 0 .../editoast_schemas/src/train_schedule/path_item.rs | 2 +- editoast/src/converters/generate_routes.rs | 2 +- editoast/src/converters/osm_to_railjson.rs | 2 +- editoast/src/converters/utils.rs | 11 +++++------ editoast/src/core/v2/path_properties.rs | 2 +- editoast/src/core/v2/pathfinding.rs | 4 ++-- editoast/src/core/v2/simulation.rs | 2 +- editoast/src/infra_cache/graph.rs | 4 ++-- editoast/src/infra_cache/mod.rs | 4 ++-- .../object_cache/operational_point_cache.rs | 2 +- .../src/views/infra/auto_fixes/electrifications.rs | 2 +- editoast/src/views/infra/auto_fixes/mod.rs | 2 +- editoast/src/views/infra/auto_fixes/speed_section.rs | 2 +- editoast/src/views/infra/auto_fixes/track_section.rs | 2 +- editoast/src/views/infra/pathfinding.rs | 4 ++-- editoast/src/views/timetable/import.rs | 2 +- editoast/src/views/train_schedule/projection.rs | 2 +- .../src/views/train_schedule/simulation_report.rs | 2 +- editoast/src/views/v2/train_schedule.rs | 2 +- 44 files changed, 54 insertions(+), 51 deletions(-) rename editoast/{editoast_common/src => editoast_schemas/src/primitives}/identifier.rs (100%) diff --git a/editoast/Cargo.lock b/editoast/Cargo.lock index 4edd0eac3a9..e7ed3ce0fbd 100644 --- a/editoast/Cargo.lock +++ b/editoast/Cargo.lock @@ -1454,7 +1454,6 @@ dependencies = [ "serde_json", "thiserror", "utoipa", - "uuid", ] [[package]] @@ -1479,12 +1478,15 @@ dependencies = [ "enum-map", "geojson", "iso8601", + "rand 0.8.5", + "rangemap", "serde", "serde_derive", "serde_json", "strum", "thiserror", "utoipa", + "uuid", ] [[package]] diff --git a/editoast/editoast_common/Cargo.toml b/editoast/editoast_common/Cargo.toml index 1f9ceb0b268..882cdf3ad28 100644 --- a/editoast/editoast_common/Cargo.toml +++ b/editoast/editoast_common/Cargo.toml @@ -15,4 +15,3 @@ serde_derive.workspace = true serde_json.workspace = true thiserror.workspace = true utoipa.workspace = true -uuid.workspace = true diff --git a/editoast/editoast_common/src/lib.rs b/editoast/editoast_common/src/lib.rs index 8ac3b8651c8..698311bc023 100644 --- a/editoast/editoast_common/src/lib.rs +++ b/editoast/editoast_common/src/lib.rs @@ -1,13 +1,11 @@ pub mod geometry; mod hash_rounded_float; -mod identifier; mod non_blank_string; pub mod rangemap_utils; pub mod schemas; pub use hash_rounded_float::hash_float; pub use hash_rounded_float::hash_float_slice; -pub use identifier::Identifier; pub use non_blank_string::NonBlankString; schemas! { diff --git a/editoast/editoast_schemas/Cargo.toml b/editoast/editoast_schemas/Cargo.toml index c125404ac44..fd3e24dc1b7 100644 --- a/editoast/editoast_schemas/Cargo.toml +++ b/editoast/editoast_schemas/Cargo.toml @@ -11,9 +11,12 @@ editoast_common.workspace = true enum-map.workspace = true geojson.workspace = true iso8601 = "0.6.1" +rand.workspace = true +rangemap.workspace = true serde.workspace = true serde_derive.workspace = true serde_json.workspace = true strum.workspace = true thiserror.workspace = true utoipa.workspace = true +uuid.workspace = true diff --git a/editoast/editoast_schemas/src/infra/applicable_directions_track_range.rs b/editoast/editoast_schemas/src/infra/applicable_directions_track_range.rs index 2adf4704135..a203c02c672 100644 --- a/editoast/editoast_schemas/src/infra/applicable_directions_track_range.rs +++ b/editoast/editoast_schemas/src/infra/applicable_directions_track_range.rs @@ -1,9 +1,9 @@ use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; use super::ApplicableDirections; +use crate::primitives::Identifier; #[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)] #[serde(deny_unknown_fields)] diff --git a/editoast/editoast_schemas/src/infra/buffer_stop.rs b/editoast/editoast_schemas/src/infra/buffer_stop.rs index d039e5de7b5..f48432dd054 100644 --- a/editoast/editoast_schemas/src/infra/buffer_stop.rs +++ b/editoast/editoast_schemas/src/infra/buffer_stop.rs @@ -1,8 +1,8 @@ use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; +use crate::primitives::Identifier; use crate::primitives::OSRDIdentified; use crate::primitives::OSRDTyped; use crate::primitives::ObjectType; diff --git a/editoast/editoast_schemas/src/infra/detector.rs b/editoast/editoast_schemas/src/infra/detector.rs index b04883e0a06..b3ed4476251 100644 --- a/editoast/editoast_schemas/src/infra/detector.rs +++ b/editoast/editoast_schemas/src/infra/detector.rs @@ -1,8 +1,8 @@ use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; +use crate::primitives::Identifier; use crate::primitives::OSRDIdentified; use crate::primitives::OSRDTyped; use crate::primitives::ObjectType; diff --git a/editoast/editoast_schemas/src/infra/directional_track_range.rs b/editoast/editoast_schemas/src/infra/directional_track_range.rs index 82ba01dee6d..4954ed75453 100644 --- a/editoast/editoast_schemas/src/infra/directional_track_range.rs +++ b/editoast/editoast_schemas/src/infra/directional_track_range.rs @@ -1,10 +1,10 @@ use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; use super::Direction; +use crate::primitives::Identifier; editoast_common::schemas! { DirectionalTrackRange, diff --git a/editoast/editoast_schemas/src/infra/electrification.rs b/editoast/editoast_schemas/src/infra/electrification.rs index c77fefcf1a4..f30b1a3133e 100644 --- a/editoast/editoast_schemas/src/infra/electrification.rs +++ b/editoast/editoast_schemas/src/infra/electrification.rs @@ -1,10 +1,10 @@ use derivative::Derivative; -use editoast_common::Identifier; use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; use super::ApplicableDirectionsTrackRange; +use crate::primitives::Identifier; use crate::primitives::OSRDIdentified; use crate::primitives::OSRDTyped; use crate::primitives::ObjectType; diff --git a/editoast/editoast_schemas/src/infra/neutral_section.rs b/editoast/editoast_schemas/src/infra/neutral_section.rs index f774537ea63..13ee8dac92c 100644 --- a/editoast/editoast_schemas/src/infra/neutral_section.rs +++ b/editoast/editoast_schemas/src/infra/neutral_section.rs @@ -1,10 +1,10 @@ use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; use super::DirectionalTrackRange; use super::Sign; +use crate::primitives::Identifier; use crate::primitives::OSRDIdentified; use crate::primitives::OSRDTyped; use crate::primitives::ObjectType; diff --git a/editoast/editoast_schemas/src/infra/operational_point.rs b/editoast/editoast_schemas/src/infra/operational_point.rs index 912189f8315..9c6421e3c2c 100644 --- a/editoast/editoast_schemas/src/infra/operational_point.rs +++ b/editoast/editoast_schemas/src/infra/operational_point.rs @@ -1,11 +1,11 @@ use derivative::Derivative; -use editoast_common::Identifier; use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; use super::TrackOffset; +use crate::primitives::Identifier; use crate::primitives::OSRDIdentified; use crate::primitives::OSRDTyped; use crate::primitives::ObjectType; diff --git a/editoast/editoast_schemas/src/infra/route.rs b/editoast/editoast_schemas/src/infra/route.rs index 990a71a66d2..08c7326f177 100644 --- a/editoast/editoast_schemas/src/infra/route.rs +++ b/editoast/editoast_schemas/src/infra/route.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/sign.rs b/editoast/editoast_schemas/src/infra/sign.rs index e14c189d50e..80eec509320 100644 --- a/editoast/editoast_schemas/src/infra/sign.rs +++ b/editoast/editoast_schemas/src/infra/sign.rs @@ -1,5 +1,5 @@ +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/signal.rs b/editoast/editoast_schemas/src/infra/signal.rs index 994d902767c..f87701bc70f 100644 --- a/editoast/editoast_schemas/src/infra/signal.rs +++ b/editoast/editoast_schemas/src/infra/signal.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/speed_section.rs b/editoast/editoast_schemas/src/infra/speed_section.rs index bf136e7ccc8..6d32311c451 100644 --- a/editoast/editoast_schemas/src/infra/speed_section.rs +++ b/editoast/editoast_schemas/src/infra/speed_section.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/switch.rs b/editoast/editoast_schemas/src/infra/switch.rs index 92fc265a0df..a9b78493cc3 100644 --- a/editoast/editoast_schemas/src/infra/switch.rs +++ b/editoast/editoast_schemas/src/infra/switch.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/switch_type.rs b/editoast/editoast_schemas/src/infra/switch_type.rs index 17d8da848ff..92a8c26cf7a 100644 --- a/editoast/editoast_schemas/src/infra/switch_type.rs +++ b/editoast/editoast_schemas/src/infra/switch_type.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/track_endpoint.rs b/editoast/editoast_schemas/src/infra/track_endpoint.rs index bcf00817d36..a07c11bb4f9 100644 --- a/editoast/editoast_schemas/src/infra/track_endpoint.rs +++ b/editoast/editoast_schemas/src/infra/track_endpoint.rs @@ -1,5 +1,5 @@ +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/track_location.rs b/editoast/editoast_schemas/src/infra/track_location.rs index 0f7f0764dc5..c0beacf0c2d 100644 --- a/editoast/editoast_schemas/src/infra/track_location.rs +++ b/editoast/editoast_schemas/src/infra/track_location.rs @@ -1,4 +1,4 @@ -use editoast_common::Identifier; +use crate::primitives::Identifier; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/infra/track_offset.rs b/editoast/editoast_schemas/src/infra/track_offset.rs index a8d824088a4..236acc0582d 100644 --- a/editoast/editoast_schemas/src/infra/track_offset.rs +++ b/editoast/editoast_schemas/src/infra/track_offset.rs @@ -1,4 +1,4 @@ -use editoast_common::Identifier; +use crate::primitives::Identifier; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/infra/track_range.rs b/editoast/editoast_schemas/src/infra/track_range.rs index 5c603c8b5d5..a7ebb4e9594 100644 --- a/editoast/editoast_schemas/src/infra/track_range.rs +++ b/editoast/editoast_schemas/src/infra/track_range.rs @@ -1,5 +1,5 @@ +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/infra/track_section.rs b/editoast/editoast_schemas/src/infra/track_section.rs index 78b5b9e2b8d..8020f24cf38 100644 --- a/editoast/editoast_schemas/src/infra/track_section.rs +++ b/editoast/editoast_schemas/src/infra/track_section.rs @@ -1,5 +1,5 @@ +use crate::primitives::Identifier; use derivative::Derivative; -use editoast_common::Identifier; use geojson::Geometry; use geojson::Value::LineString; use serde::Deserialize; diff --git a/editoast/editoast_schemas/src/infra/waypoint.rs b/editoast/editoast_schemas/src/infra/waypoint.rs index 094cdf5ac6c..4f0a7b8690b 100644 --- a/editoast/editoast_schemas/src/infra/waypoint.rs +++ b/editoast/editoast_schemas/src/infra/waypoint.rs @@ -1,4 +1,4 @@ -use editoast_common::Identifier; +use crate::primitives::Identifier; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/primitives.rs b/editoast/editoast_schemas/src/primitives.rs index 4ea8bc10e86..5de5d1e187a 100644 --- a/editoast/editoast_schemas/src/primitives.rs +++ b/editoast/editoast_schemas/src/primitives.rs @@ -1,11 +1,13 @@ mod bounding_box; pub mod duration; +mod identifier; mod object_ref; mod object_type; mod zone; pub use bounding_box::BoundingBox; pub use duration::PositiveDuration; +pub use identifier::Identifier; pub use object_ref::ObjectRef; pub use object_type::ObjectType; pub use zone::Zone; diff --git a/editoast/editoast_common/src/identifier.rs b/editoast/editoast_schemas/src/primitives/identifier.rs similarity index 100% rename from editoast/editoast_common/src/identifier.rs rename to editoast/editoast_schemas/src/primitives/identifier.rs diff --git a/editoast/editoast_schemas/src/train_schedule/path_item.rs b/editoast/editoast_schemas/src/train_schedule/path_item.rs index 0559b1a6de6..ff53be6c39c 100644 --- a/editoast/editoast_schemas/src/train_schedule/path_item.rs +++ b/editoast/editoast_schemas/src/train_schedule/path_item.rs @@ -1,4 +1,4 @@ -use editoast_common::Identifier; +use crate::primitives::Identifier; use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/src/converters/generate_routes.rs b/editoast/src/converters/generate_routes.rs index 5571aaa2372..9006ec00230 100644 --- a/editoast/src/converters/generate_routes.rs +++ b/editoast/src/converters/generate_routes.rs @@ -6,7 +6,6 @@ use std::collections::HashMap; -use editoast_common::Identifier; use editoast_schemas::infra::builtin_node_types_list; use editoast_schemas::infra::Direction; use editoast_schemas::infra::Endpoint; @@ -14,6 +13,7 @@ use editoast_schemas::infra::RailJson; use editoast_schemas::infra::Route; use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::infra::Waypoint; +use editoast_schemas::primitives::Identifier; use editoast_schemas::primitives::OSRDIdentified; /* Part 1: type definitions */ diff --git a/editoast/src/converters/osm_to_railjson.rs b/editoast/src/converters/osm_to_railjson.rs index 67959cf728b..24db408c810 100644 --- a/editoast/src/converters/osm_to_railjson.rs +++ b/editoast/src/converters/osm_to_railjson.rs @@ -128,10 +128,10 @@ 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 editoast_common::Identifier; use editoast_schemas::infra::Endpoint; + use editoast_schemas::primitives::Identifier; #[test] fn create_empty_graph() { diff --git a/editoast/src/infra_cache/mod.rs b/editoast/src/infra_cache/mod.rs index 3ce94e37486..1fe2b9338f9 100644 --- a/editoast/src/infra_cache/mod.rs +++ b/editoast/src/infra_cache/mod.rs @@ -862,7 +862,6 @@ pub mod tests { use crate::infra_cache::InfraCache; use crate::infra_cache::SwitchCache; use crate::modelsv2::infra::tests::test_infra_transaction; - use editoast_common::Identifier; use editoast_common::NonBlankString; use editoast_schemas::infra::ApplicableDirections; use editoast_schemas::infra::ApplicableDirectionsTrackRange; @@ -877,6 +876,7 @@ pub mod tests { use editoast_schemas::infra::SwitchType; use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::primitives::BoundingBox; + use editoast_schemas::primitives::Identifier; use editoast_schemas::primitives::OSRDIdentified; #[actix_test] @@ -1400,10 +1400,10 @@ pub mod tests { use crate::infra_cache::tests::create_switch_type_cache; use crate::infra_cache::InfraCache; use crate::infra_cache::InfraCacheEditoastError; - 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::Identifier; use editoast_schemas::primitives::ObjectType; #[test] diff --git a/editoast/src/infra_cache/object_cache/operational_point_cache.rs b/editoast/src/infra_cache/object_cache/operational_point_cache.rs index adda0b324a2..41262fecd8a 100644 --- a/editoast/src/infra_cache/object_cache/operational_point_cache.rs +++ b/editoast/src/infra_cache/object_cache/operational_point_cache.rs @@ -1,5 +1,5 @@ use derivative::Derivative; -use editoast_common::Identifier; +use editoast_schemas::primitives::Identifier; use editoast_schemas::primitives::OSRDIdentified; use editoast_schemas::primitives::OSRDTyped; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/views/infra/auto_fixes/electrifications.rs b/editoast/src/views/infra/auto_fixes/electrifications.rs index 36f59b8513d..a3c59143553 100644 --- a/editoast/src/views/infra/auto_fixes/electrifications.rs +++ b/editoast/src/views/infra/auto_fixes/electrifications.rs @@ -95,10 +95,10 @@ mod tests { use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::operation::Operation; use crate::infra_cache::ObjectCache; - use editoast_common::Identifier; use editoast_schemas::infra::ApplicableDirections; use editoast_schemas::infra::ApplicableDirectionsTrackRange; use editoast_schemas::infra::Electrification; + use editoast_schemas::primitives::Identifier; use editoast_schemas::primitives::OSRDObject as _; use editoast_schemas::primitives::ObjectRef; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/views/infra/auto_fixes/mod.rs b/editoast/src/views/infra/auto_fixes/mod.rs index bf8a1c9c6cb..c25b3e1994d 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::infra_cache::InfraCacheEditoastError; use crate::views::pagination::PaginatedResponse; use crate::views::tests::create_test_service; - use editoast_common::Identifier; use editoast_schemas::infra::ApplicableDirectionsTrackRange; use editoast_schemas::infra::Detector; use editoast_schemas::infra::Electrification; @@ -355,6 +354,7 @@ mod tests { use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::infra::TrackSection; use editoast_schemas::infra::Waypoint; + use editoast_schemas::primitives::Identifier; use editoast_schemas::primitives::ObjectRef; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/views/infra/auto_fixes/speed_section.rs b/editoast/src/views/infra/auto_fixes/speed_section.rs index ec421089669..2e561acae86 100644 --- a/editoast/src/views/infra/auto_fixes/speed_section.rs +++ b/editoast/src/views/infra/auto_fixes/speed_section.rs @@ -95,10 +95,10 @@ mod tests { use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::operation::Operation; use crate::infra_cache::ObjectCache; - use editoast_common::Identifier; use editoast_schemas::infra::ApplicableDirections; use editoast_schemas::infra::ApplicableDirectionsTrackRange; use editoast_schemas::infra::SpeedSection; + use editoast_schemas::primitives::Identifier; use editoast_schemas::primitives::OSRDObject as _; 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 290dff629af..49606f38572 100644 --- a/editoast/src/views/infra/auto_fixes/track_section.rs +++ b/editoast/src/views/infra/auto_fixes/track_section.rs @@ -9,9 +9,9 @@ use crate::generated_data::infra_error::InfraError; use crate::generated_data::infra_error::InfraErrorType; use crate::infra_cache::object_cache::TrackSectionCache; use crate::infra_cache::operation::RailjsonObject; -use editoast_common::Identifier; use editoast_schemas::infra::BufferStop; use editoast_schemas::infra::Endpoint; +use editoast_schemas::primitives::Identifier; 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 92637ebf500..e9c1748f597 100644 --- a/editoast/src/views/infra/pathfinding.rs +++ b/editoast/src/views/infra/pathfinding.rs @@ -23,11 +23,11 @@ use crate::modelsv2::Infra; 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::Identifier; use editoast_schemas::primitives::ObjectType; crate::routes! { @@ -413,9 +413,9 @@ mod tests { use crate::infra_cache::Graph; use crate::views::infra::pathfinding::PathfindingInput; use crate::views::infra::pathfinding::PathfindingTrackLocationInput; - use editoast_common::Identifier; use editoast_schemas::infra::Direction; use editoast_schemas::infra::DirectionalTrackRange; + use editoast_schemas::primitives::Identifier; fn expected_path() -> Vec { vec![ diff --git a/editoast/src/views/timetable/import.rs b/editoast/src/views/timetable/import.rs index d89524bda56..22b1abdb0f6 100644 --- a/editoast/src/views/timetable/import.rs +++ b/editoast/src/views/timetable/import.rs @@ -580,7 +580,7 @@ fn build_simulation_request( #[cfg(test)] mod tests { use super::*; - use editoast_common::Identifier; + use editoast_schemas::primitives::Identifier; #[test] fn test_waypoints_from_steps() { diff --git a/editoast/src/views/train_schedule/projection.rs b/editoast/src/views/train_schedule/projection.rs index 804ce873cce..3aa9bfc2bc6 100644 --- a/editoast/src/views/train_schedule/projection.rs +++ b/editoast/src/views/train_schedule/projection.rs @@ -4,8 +4,8 @@ use serde::Deserialize; use serde::Serialize; use crate::models::PathfindingPayload; -use editoast_common::Identifier; use editoast_schemas::infra::DirectionalTrackRange; +use editoast_schemas::primitives::Identifier; #[derive(Debug, Serialize, Deserialize)] pub struct Projection { diff --git a/editoast/src/views/train_schedule/simulation_report.rs b/editoast/src/views/train_schedule/simulation_report.rs index b3df5643363..e2a6521f599 100644 --- a/editoast/src/views/train_schedule/simulation_report.rs +++ b/editoast/src/views/train_schedule/simulation_report.rs @@ -34,7 +34,7 @@ use crate::views::pathfinding::make_track_map; use crate::views::train_schedule::projection::Projection; use crate::views::train_schedule::TrainScheduleError::UnsimulatedTrainSchedule; use crate::DbPool; -use editoast_common::Identifier; +use editoast_schemas::primitives::Identifier; editoast_common::schemas! { SimulationReport, diff --git a/editoast/src/views/v2/train_schedule.rs b/editoast/src/views/v2/train_schedule.rs index 02781548195..4df469311c9 100644 --- a/editoast/src/views/v2/train_schedule.rs +++ b/editoast/src/views/v2/train_schedule.rs @@ -34,7 +34,7 @@ use crate::views::v2::path::PathfindingError; use crate::DbPool; use crate::RedisClient; use crate::RollingStockModel; -use editoast_common::Identifier; +use editoast_schemas::primitives::Identifier; use actix_web::web::{Data, Json, Path, Query}; use actix_web::{delete, get, post, put, HttpResponse}; From 8fee1ef789b059bd5cf3fb8be09ad4fa454ebd26 Mon Sep 17 00:00:00 2001 From: hamz2a Date: Tue, 23 Apr 2024 11:42:36 +0200 Subject: [PATCH 7/7] editoast: move NonBlankString to editoast_schemas::primitives --- editoast/Cargo.lock | 1 - editoast/editoast_common/Cargo.toml | 1 - editoast/editoast_common/src/lib.rs | 2 -- editoast/editoast_schemas/src/infra/electrification.rs | 2 +- editoast/editoast_schemas/src/infra/operational_point.rs | 2 +- editoast/editoast_schemas/src/infra/sign.rs | 2 +- editoast/editoast_schemas/src/infra/signal.rs | 2 +- editoast/editoast_schemas/src/infra/speed_section.rs | 2 +- editoast/editoast_schemas/src/infra/switch.rs | 2 +- .../editoast_schemas/src/infra/track_section_sncf_extension.rs | 2 +- .../src/infra/track_section_source_extension.rs | 2 +- editoast/editoast_schemas/src/primitives.rs | 2 ++ .../src => editoast_schemas/src/primitives}/non_blank_string.rs | 0 editoast/editoast_schemas/src/train_schedule/margins.rs | 2 +- editoast/editoast_schemas/src/train_schedule/path_item.rs | 2 +- .../src/train_schedule/power_restriction_item.rs | 2 +- editoast/editoast_schemas/src/train_schedule/schedule_item.rs | 2 +- .../editoast_schemas/src/train_schedule/train_schedule_base.rs | 2 +- editoast/src/infra_cache/mod.rs | 2 +- 19 files changed, 16 insertions(+), 18 deletions(-) rename editoast/{editoast_common/src => editoast_schemas/src/primitives}/non_blank_string.rs (100%) diff --git a/editoast/Cargo.lock b/editoast/Cargo.lock index e7ed3ce0fbd..3572faf1de6 100644 --- a/editoast/Cargo.lock +++ b/editoast/Cargo.lock @@ -1447,7 +1447,6 @@ version = "0.1.0" dependencies = [ "chrono", "geos", - "rand 0.8.5", "rangemap", "serde", "serde_derive", diff --git a/editoast/editoast_common/Cargo.toml b/editoast/editoast_common/Cargo.toml index 882cdf3ad28..54b71227fbc 100644 --- a/editoast/editoast_common/Cargo.toml +++ b/editoast/editoast_common/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] chrono.workspace = true geos.workspace = true -rand.workspace = true rangemap.workspace = true serde.workspace = true serde_derive.workspace = true diff --git a/editoast/editoast_common/src/lib.rs b/editoast/editoast_common/src/lib.rs index 698311bc023..c7e38d3b550 100644 --- a/editoast/editoast_common/src/lib.rs +++ b/editoast/editoast_common/src/lib.rs @@ -1,12 +1,10 @@ pub mod geometry; mod hash_rounded_float; -mod non_blank_string; pub mod rangemap_utils; pub mod schemas; pub use hash_rounded_float::hash_float; pub use hash_rounded_float::hash_float_slice; -pub use non_blank_string::NonBlankString; schemas! { geometry::schemas(), diff --git a/editoast/editoast_schemas/src/infra/electrification.rs b/editoast/editoast_schemas/src/infra/electrification.rs index f30b1a3133e..cde61cfbd64 100644 --- a/editoast/editoast_schemas/src/infra/electrification.rs +++ b/editoast/editoast_schemas/src/infra/electrification.rs @@ -1,5 +1,5 @@ +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/operational_point.rs b/editoast/editoast_schemas/src/infra/operational_point.rs index 9c6421e3c2c..5b22b625d26 100644 --- a/editoast/editoast_schemas/src/infra/operational_point.rs +++ b/editoast/editoast_schemas/src/infra/operational_point.rs @@ -1,5 +1,5 @@ +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/infra/sign.rs b/editoast/editoast_schemas/src/infra/sign.rs index 80eec509320..e431497667c 100644 --- a/editoast/editoast_schemas/src/infra/sign.rs +++ b/editoast/editoast_schemas/src/infra/sign.rs @@ -1,6 +1,6 @@ use crate::primitives::Identifier; +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/signal.rs b/editoast/editoast_schemas/src/infra/signal.rs index f87701bc70f..01c81593c09 100644 --- a/editoast/editoast_schemas/src/infra/signal.rs +++ b/editoast/editoast_schemas/src/infra/signal.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use crate::primitives::Identifier; +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/speed_section.rs b/editoast/editoast_schemas/src/infra/speed_section.rs index 6d32311c451..eb680cfc726 100644 --- a/editoast/editoast_schemas/src/infra/speed_section.rs +++ b/editoast/editoast_schemas/src/infra/speed_section.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use crate::primitives::Identifier; +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/switch.rs b/editoast/editoast_schemas/src/infra/switch.rs index a9b78493cc3..267274080fa 100644 --- a/editoast/editoast_schemas/src/infra/switch.rs +++ b/editoast/editoast_schemas/src/infra/switch.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use crate::primitives::Identifier; +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/track_section_sncf_extension.rs b/editoast/editoast_schemas/src/infra/track_section_sncf_extension.rs index a73ab13f5c2..0005e4011c6 100644 --- a/editoast/editoast_schemas/src/infra/track_section_sncf_extension.rs +++ b/editoast/editoast_schemas/src/infra/track_section_sncf_extension.rs @@ -1,5 +1,5 @@ +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/infra/track_section_source_extension.rs b/editoast/editoast_schemas/src/infra/track_section_source_extension.rs index 364d34a7bc5..00b40e97c89 100644 --- a/editoast/editoast_schemas/src/infra/track_section_source_extension.rs +++ b/editoast/editoast_schemas/src/infra/track_section_source_extension.rs @@ -1,5 +1,5 @@ +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/editoast_schemas/src/primitives.rs b/editoast/editoast_schemas/src/primitives.rs index 5de5d1e187a..03626695ba1 100644 --- a/editoast/editoast_schemas/src/primitives.rs +++ b/editoast/editoast_schemas/src/primitives.rs @@ -1,6 +1,7 @@ mod bounding_box; pub mod duration; mod identifier; +mod non_blank_string; mod object_ref; mod object_type; mod zone; @@ -8,6 +9,7 @@ mod zone; pub use bounding_box::BoundingBox; pub use duration::PositiveDuration; pub use identifier::Identifier; +pub use non_blank_string::NonBlankString; pub use object_ref::ObjectRef; pub use object_type::ObjectType; pub use zone::Zone; diff --git a/editoast/editoast_common/src/non_blank_string.rs b/editoast/editoast_schemas/src/primitives/non_blank_string.rs similarity index 100% rename from editoast/editoast_common/src/non_blank_string.rs rename to editoast/editoast_schemas/src/primitives/non_blank_string.rs diff --git a/editoast/editoast_schemas/src/train_schedule/margins.rs b/editoast/editoast_schemas/src/train_schedule/margins.rs index 937182ee212..adb44c75f52 100644 --- a/editoast/editoast_schemas/src/train_schedule/margins.rs +++ b/editoast/editoast_schemas/src/train_schedule/margins.rs @@ -1,7 +1,7 @@ use std::str::FromStr; +use crate::primitives::NonBlankString; use derivative::Derivative; -use editoast_common::NonBlankString; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/train_schedule/path_item.rs b/editoast/editoast_schemas/src/train_schedule/path_item.rs index ff53be6c39c..fcf48d7472a 100644 --- a/editoast/editoast_schemas/src/train_schedule/path_item.rs +++ b/editoast/editoast_schemas/src/train_schedule/path_item.rs @@ -1,5 +1,5 @@ use crate::primitives::Identifier; -use editoast_common::NonBlankString; +use crate::primitives::NonBlankString; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/train_schedule/power_restriction_item.rs b/editoast/editoast_schemas/src/train_schedule/power_restriction_item.rs index 3b9179722af..424e3e16ff6 100644 --- a/editoast/editoast_schemas/src/train_schedule/power_restriction_item.rs +++ b/editoast/editoast_schemas/src/train_schedule/power_restriction_item.rs @@ -1,4 +1,4 @@ -use editoast_common::NonBlankString; +use crate::primitives::NonBlankString; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/train_schedule/schedule_item.rs b/editoast/editoast_schemas/src/train_schedule/schedule_item.rs index bf5a58f92a7..5c968e3c369 100644 --- a/editoast/editoast_schemas/src/train_schedule/schedule_item.rs +++ b/editoast/editoast_schemas/src/train_schedule/schedule_item.rs @@ -1,4 +1,4 @@ -use editoast_common::NonBlankString; +use crate::primitives::NonBlankString; use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; diff --git a/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs b/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs index 7f0956848e7..7e21058de96 100644 --- a/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs +++ b/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; use std::collections::HashSet; +use crate::primitives::NonBlankString; use chrono::DateTime; use chrono::Utc; -use editoast_common::NonBlankString; use serde::de::Error as SerdeError; use serde::Deserialize; use serde::Serialize; diff --git a/editoast/src/infra_cache/mod.rs b/editoast/src/infra_cache/mod.rs index 1fe2b9338f9..c87d8e4e7e3 100644 --- a/editoast/src/infra_cache/mod.rs +++ b/editoast/src/infra_cache/mod.rs @@ -862,7 +862,6 @@ pub mod tests { use crate::infra_cache::InfraCache; use crate::infra_cache::SwitchCache; use crate::modelsv2::infra::tests::test_infra_transaction; - use editoast_common::NonBlankString; use editoast_schemas::infra::ApplicableDirections; use editoast_schemas::infra::ApplicableDirectionsTrackRange; use editoast_schemas::infra::Direction; @@ -877,6 +876,7 @@ pub mod tests { use editoast_schemas::infra::TrackEndpoint; use editoast_schemas::primitives::BoundingBox; use editoast_schemas::primitives::Identifier; + use editoast_schemas::primitives::NonBlankString; use editoast_schemas::primitives::OSRDIdentified; #[actix_test]