diff --git a/editoast/editoast_schemas/src/infra.rs b/editoast/editoast_schemas/src/infra.rs index f83a483ef2d..798b660a845 100644 --- a/editoast/editoast_schemas/src/infra.rs +++ b/editoast/editoast_schemas/src/infra.rs @@ -1,9 +1,11 @@ mod direction; mod track_offset; +mod track_range; mod waypoint; pub use direction::Direction; pub use track_offset::TrackOffset; +pub use track_range::TrackRange; pub use waypoint::Waypoint; editoast_common::schemas! { diff --git a/editoast/editoast_schemas/src/infra/track_range.rs b/editoast/editoast_schemas/src/infra/track_range.rs new file mode 100644 index 00000000000..5c603c8b5d5 --- /dev/null +++ b/editoast/editoast_schemas/src/infra/track_range.rs @@ -0,0 +1,27 @@ +use derivative::Derivative; +use editoast_common::Identifier; +use serde::Deserialize; +use serde::Serialize; +use utoipa::ToSchema; + +#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)] +#[serde(deny_unknown_fields)] +#[derivative(Default)] +pub struct TrackRange { + #[schema(value_type=String, example="01234567-89ab-cdef-0123-456789abcdef")] + #[derivative(Default(value = r#""InvalidRef".into()"#))] + pub track: Identifier, + pub begin: f64, + #[derivative(Default(value = "100."))] + pub end: f64, +} + +impl TrackRange { + pub fn new>(track: T, begin: f64, end: f64) -> Self { + Self { + track: track.as_ref().into(), + begin, + end, + } + } +} diff --git a/editoast/src/fixtures.rs b/editoast/src/fixtures.rs index 60feb17649e..6a390a7cb50 100644 --- a/editoast/src/fixtures.rs +++ b/editoast/src/fixtures.rs @@ -19,7 +19,7 @@ pub mod tests { schema::{ electrical_profiles::{ElectricalProfile, ElectricalProfileSetData}, v2::trainschedule::TrainScheduleBase, - RailJson, TrackRange, + RailJson, }, views::{ rolling_stocks::rolling_stock_form::RollingStockForm, @@ -31,6 +31,7 @@ pub mod tests { use actix_web::web::Data; use chrono::Utc; use diesel_async::pooled_connection::AsyncDieselConnectionManager; + use editoast_schemas::infra::TrackRange; use futures::executor; use postgis_diesel::types::LineString; use rstest::*; diff --git a/editoast/src/modelsv2/work_schedules.rs b/editoast/src/modelsv2/work_schedules.rs index 488b4d2cd6d..9a618f83eea 100644 --- a/editoast/src/modelsv2/work_schedules.rs +++ b/editoast/src/modelsv2/work_schedules.rs @@ -1,6 +1,6 @@ -use crate::schema::TrackRange; use chrono::NaiveDateTime; use editoast_derive::ModelV2; +use editoast_schemas::infra::TrackRange; use strum::FromRepr; use serde::Deserialize; diff --git a/editoast/src/schema/electrical_profiles.rs b/editoast/src/schema/electrical_profiles.rs index 934189dba81..745734f6dc4 100644 --- a/editoast/src/schema/electrical_profiles.rs +++ b/editoast/src/schema/electrical_profiles.rs @@ -4,7 +4,7 @@ use serde::Deserialize; use serde::Serialize; use utoipa::ToSchema; -use crate::schema::TrackRange; +use editoast_schemas::infra::TrackRange; #[derive(Debug, Serialize, Deserialize, PartialEq, Clone, ToSchema)] pub struct ElectricalProfile { diff --git a/editoast/src/schema/mod.rs b/editoast/src/schema/mod.rs index 457852bad48..b8a0af5377f 100644 --- a/editoast/src/schema/mod.rs +++ b/editoast/src/schema/mod.rs @@ -79,28 +79,6 @@ editoast_common::schemas! { operation::schemas(), } -#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)] -#[serde(deny_unknown_fields)] -#[derivative(Default)] -pub struct TrackRange { - #[schema(value_type=String, example="01234567-89ab-cdef-0123-456789abcdef")] - #[derivative(Default(value = r#""InvalidRef".into()"#))] - pub track: Identifier, - pub begin: f64, - #[derivative(Default(value = "100."))] - pub end: f64, -} - -impl TrackRange { - pub fn new>(track: T, begin: f64, end: f64) -> Self { - Self { - track: track.as_ref().into(), - begin, - end, - } - } -} - #[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)] #[serde(deny_unknown_fields)] #[derivative(Default)] diff --git a/editoast/src/views/electrical_profiles.rs b/editoast/src/views/electrical_profiles.rs index cc489c3172d..f769256e44f 100644 --- a/editoast/src/views/electrical_profiles.rs +++ b/editoast/src/views/electrical_profiles.rs @@ -23,8 +23,8 @@ use crate::modelsv2::Retrieve; use crate::schema::electrical_profiles::ElectricalProfile; use crate::schema::electrical_profiles::ElectricalProfileSetData; use crate::schema::electrical_profiles::LevelValues; -use crate::schema::TrackRange; use crate::DbPool; +use editoast_schemas::infra::TrackRange; crate::routes! { "/electrical_profile_set" => { @@ -197,8 +197,8 @@ mod tests { use crate::fixtures::tests::electrical_profile_set; use crate::fixtures::tests::TestFixture; use crate::schema::electrical_profiles::ElectricalProfile; - use crate::schema::TrackRange; use crate::views::tests::create_test_service; + use editoast_schemas::infra::TrackRange; #[rstest] async fn test_list( diff --git a/editoast/src/views/pathfinding/electrical_profiles.rs b/editoast/src/views/pathfinding/electrical_profiles.rs index 83b687cba67..a279dbc9b44 100644 --- a/editoast/src/views/pathfinding/electrical_profiles.rs +++ b/editoast/src/views/pathfinding/electrical_profiles.rs @@ -153,8 +153,8 @@ mod tests { use crate::modelsv2::prelude::*; use crate::modelsv2::Infra; use crate::schema::electrical_profiles::ElectricalProfile; - use crate::schema::TrackRange; use crate::views::tests::create_test_service; + use editoast_schemas::infra::TrackRange; #[fixture] async fn electrical_profile_set(db_pool: Data) -> TestFixture { diff --git a/editoast/src/views/pathfinding/mod.rs b/editoast/src/views/pathfinding/mod.rs index 27b7f81ccd5..4b9518e8c07 100644 --- a/editoast/src/views/pathfinding/mod.rs +++ b/editoast/src/views/pathfinding/mod.rs @@ -52,11 +52,11 @@ use crate::modelsv2::Retrieve as RetrieveV2; use crate::modelsv2::RollingStockModel; use crate::schema::ApplicableDirectionsTrackRange; use crate::schema::OperationalPoint; -use crate::schema::TrackRange; use crate::schema::TrackSection; use crate::DbPool; use editoast_common::geometry::diesel_linestring_to_geojson; use editoast_common::geometry::geojson_to_diesel_linestring; +use editoast_schemas::infra::TrackRange; crate::routes! { "/pathfinding" => { diff --git a/editoast/src/views/work_schedules.rs b/editoast/src/views/work_schedules.rs index c419a9e9260..cbf83a8d666 100644 --- a/editoast/src/views/work_schedules.rs +++ b/editoast/src/views/work_schedules.rs @@ -21,8 +21,8 @@ use crate::modelsv2::Changeset; use crate::modelsv2::Create; use crate::modelsv2::CreateBatch; use crate::modelsv2::Model; -use crate::schema::TrackRange; use crate::DbPool; +use editoast_schemas::infra::TrackRange; crate::routes! { "/work_schedules" => {