Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast: move Endpoint and TrackEndpoint to editoast_schemas #7211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions editoast/editoast_schemas/src/infra.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions editoast/editoast_schemas/src/infra/endpoint.rs
Original file line number Diff line number Diff line change
@@ -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,
}
39 changes: 39 additions & 0 deletions editoast/editoast_schemas/src/infra/track_endpoint.rs
Original file line number Diff line number Diff line change
@@ -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<T: AsRef<str>>(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<T: AsRef<str>>(track: T, dir: Direction) -> TrackEndpoint {
let endpoint = match dir {
Direction::StartToStop => Endpoint::End,
Direction::StopToStart => Endpoint::Begin,
};
TrackEndpoint {
track: track.as_ref().into(),
endpoint,
}
}
}
2 changes: 2 additions & 0 deletions editoast/src/converters/generate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion editoast/src/converters/osm_to_railjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ pub fn parse_osm(osm_pbf_in: PathBuf) -> Result<RailJson, Box<dyn Error + Send +

#[cfg(test)]
mod tests {
use editoast_common::Identifier;
use editoast_schemas::infra::ApplicableDirections;
use editoast_schemas::infra::TrackEndpoint;
use std::collections::HashMap;

use super::parse_osm;
use crate::converters::*;
use crate::schema::*;
use editoast_common::Identifier;

#[test]
fn convert_osm_to_railjson() {
let output = tempfile::NamedTempFile::new().unwrap();
Expand Down
2 changes: 2 additions & 0 deletions editoast/src/converters/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use editoast_schemas::infra::Direction;
use std::collections::HashMap;
use std::str::FromStr;

use editoast_schemas::infra::Endpoint;
use editoast_schemas::infra::Side;
use editoast_schemas::infra::TrackEndpoint;
use osm4routing::Coord;
use osm4routing::Edge;
use osm4routing::NodeId;
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/generated_data/error/buffer_stops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::generated_data::error::ObjectErrorGenerator;
use crate::infra_cache::Graph;
use crate::infra_cache::InfraCache;
use crate::infra_cache::ObjectCache;
use crate::schema::Endpoint;
use crate::schema::InfraError;
use crate::schema::TrackEndpoint;
use editoast_schemas::infra::Endpoint;
use editoast_schemas::infra::TrackEndpoint;
use editoast_schemas::primitives::ObjectRef;
use editoast_schemas::primitives::ObjectType;

Expand Down Expand Up @@ -172,7 +172,7 @@ pub mod tests {
use crate::infra_cache::tests::create_small_infra_cache;
use crate::infra_cache::tests::create_track_section_cache;
use crate::infra_cache::Graph;
use crate::schema::Endpoint;
use editoast_schemas::infra::Endpoint;
use editoast_schemas::primitives::ObjectRef;
use editoast_schemas::primitives::ObjectType;

Expand Down
4 changes: 2 additions & 2 deletions editoast/src/generated_data/error/switches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::infra_cache::Graph;
use crate::infra_cache::InfraCache;
use crate::infra_cache::ObjectCache;
use crate::schema::InfraError;
use crate::schema::TrackEndpoint;
use editoast_schemas::infra::TrackEndpoint;
use editoast_schemas::primitives::OSRDIdentified;
use editoast_schemas::primitives::ObjectRef;
use editoast_schemas::primitives::ObjectType;
Expand Down Expand Up @@ -143,7 +143,7 @@ mod tests {
use crate::infra_cache::tests::create_small_infra_cache;
use crate::infra_cache::tests::create_switch_cache_point;
use crate::infra_cache::tests::create_track_endpoint;
use crate::schema::Endpoint;
use editoast_schemas::infra::Endpoint;
use editoast_schemas::primitives::OSRDIdentified;
use editoast_schemas::primitives::ObjectRef;
use editoast_schemas::primitives::ObjectType;
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/infra_cache/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;

use crate::infra_cache::InfraCache;
use crate::schema::SwitchCache;
use crate::schema::TrackEndpoint;
use editoast_common::Identifier;
use editoast_schemas::infra::TrackEndpoint;

#[derive(Default, Clone, Debug)]
pub struct Graph<'a> {
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/infra_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,19 +751,19 @@ 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;
use crate::schema::SpeedSection;
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]
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion editoast/src/schema/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
40 changes: 0 additions & 40 deletions editoast/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T: AsRef<str>>(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<T: AsRef<str>>(track: T, dir: Direction) -> TrackEndpoint {
let endpoint = match dir {
Direction::StartToStop => Endpoint::End,
Direction::StopToStart => Endpoint::Begin,
};
TrackEndpoint {
track: track.as_ref().into(),
endpoint,
}
}
}
4 changes: 2 additions & 2 deletions editoast/src/schema/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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;
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;

Expand Down
2 changes: 1 addition & 1 deletion editoast/src/schema/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/schema/track_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/infra/auto_fixes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/auto_fixes/track_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/infra/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
Loading