Skip to content

Commit

Permalink
editoast: move track_ranget to editoast_schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
hamz2a committed Apr 12, 2024
1 parent 102af2c commit 6289b27
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 30 deletions.
2 changes: 2 additions & 0 deletions editoast/editoast_schemas/src/infra.rs
Original file line number Diff line number Diff line change
@@ -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! {
Expand Down
27 changes: 27 additions & 0 deletions editoast/editoast_schemas/src/infra/track_range.rs
Original file line number Diff line number Diff line change
@@ -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<T: AsRef<str>>(track: T, begin: f64, end: f64) -> Self {
Self {
track: track.as_ref().into(),
begin,
end,
}
}
}
3 changes: 2 additions & 1 deletion editoast/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/modelsv2/work_schedules.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/schema/electrical_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 0 additions & 22 deletions editoast/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AsRef<str>>(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)]
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/electrical_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/pathfinding/electrical_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DbPool>) -> TestFixture<ElectricalProfileSet> {
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/pathfinding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/work_schedules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down

0 comments on commit 6289b27

Please sign in to comment.