Skip to content

Commit

Permalink
editoast: remove rolling stock common
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Apr 8, 2024
1 parent d046886 commit 038f823
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 138 deletions.
33 changes: 28 additions & 5 deletions editoast/editoast_schemas/src/rolling_stock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ pub use rolling_stock_metadata::RollingStockMetadata;
mod loading_gauge_type;
pub use loading_gauge_type::LoadingGaugeType;

mod rolling_stock_common;
pub use rolling_stock_common::RollingStockCommon;

mod rolling_stock_livery;
pub use rolling_stock_livery::RollingStockLivery;
pub use rolling_stock_livery::RollingStockLiveryMetadata;

use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use utoipa::ToSchema;

editoast_common::schemas! {
Expand All @@ -55,7 +53,6 @@ editoast_common::schemas! {
RollingStockSupportedSignalingSystems,
RollingStockMetadata,
LoadingGaugeType,
RollingStockCommon,
RollingStockLivery,
RollingStockLiveryMetadata,
}
Expand All @@ -66,7 +63,33 @@ pub const ROLLING_STOCK_RAILJSON_VERSION: &str = "3.2";
pub struct RollingStock {
pub id: i64,
#[serde(flatten)]
pub common: RollingStockCommon,
pub name: String,
pub effort_curves: EffortCurves,
#[schema(example = "5", required)]
pub base_power_class: Option<String>,
pub length: f64,
pub max_speed: f64,
pub startup_time: f64,
pub startup_acceleration: f64,
pub comfort_acceleration: f64,
pub gamma: Gamma,
pub inertia_coefficient: f64,
pub mass: f64,
pub rolling_resistance: RollingResistance,
pub loading_gauge: LoadingGaugeType,
/// Mapping of power restriction code to power class
#[serde(default)]
#[schema(required)]
pub power_restrictions: HashMap<String, String>,
#[serde(default)]
pub energy_sources: Vec<EnergySource>,
/// The time the train takes before actually using electrical power (in seconds). Is null if the train is not electric.
#[schema(example = 5.0)]
pub electrical_power_startup_time: Option<f64>,
/// The time it takes to raise this train's pantograph in seconds. Is null if the train is not electric.
#[schema(example = 15.0)]
pub raise_pantograph_time: Option<f64>,
pub supported_signaling_systems: RollingStockSupportedSignalingSystems,
pub railjson_version: String,
/// Whether the rolling stock can be edited/deleted or not.
pub locked: bool,
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions editoast/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub mod tests {
let mut rolling_stock_form: RollingStockForm =
serde_json::from_str(include_str!("./tests/example_rolling_stock_1.json"))
.expect("Unable to parse");
rolling_stock_form.common.name = name.to_string();
rolling_stock_form.name = name.to_string();
rolling_stock_form
}

Expand All @@ -172,7 +172,7 @@ pub mod tests {
"./tests/example_rolling_stock_2_energy_sources.json"
))
.expect("Unable to parse");
rolling_stock_form.common.name = name.to_string();
rolling_stock_form.name = name.to_string();
rolling_stock_form
}

Expand Down
23 changes: 7 additions & 16 deletions editoast/src/models/rolling_stock/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use editoast_schemas::rolling_stock::{RollingStock, RollingStockCommon};
use editoast_schemas::rolling_stock::RollingStock;

use crate::modelsv2::rolling_stock_model::RollingStockModel;

impl From<RollingStockModel> for RollingStockCommon {
impl From<RollingStockModel> for RollingStock {
fn from(rolling_stock_model: RollingStockModel) -> Self {
RollingStockCommon {
RollingStock {
railjson_version: rolling_stock_model.railjson_version,
id: rolling_stock_model.id,
metadata: rolling_stock_model.metadata,
locked: rolling_stock_model.locked,
name: rolling_stock_model.name,
effort_curves: rolling_stock_model.effort_curves,
base_power_class: rolling_stock_model.base_power_class,
Expand All @@ -27,19 +31,6 @@ impl From<RollingStockModel> for RollingStockCommon {
}
}

impl From<RollingStockModel> for RollingStock {
fn from(rolling_stock_model: RollingStockModel) -> Self {
let rolling_stock_common: RollingStockCommon = rolling_stock_model.clone().into();
RollingStock {
id: rolling_stock_model.id,
common: rolling_stock_common,
railjson_version: rolling_stock_model.railjson_version,
locked: rolling_stock_model.locked,
metadata: rolling_stock_model.metadata,
}
}
}

#[cfg(test)]
pub mod tests {
use actix_web::web::Data;
Expand Down
52 changes: 26 additions & 26 deletions editoast/src/views/rolling_stocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async fn create(
) -> Result<Json<RollingStock>> {
rolling_stock_form.validate()?;
let mut db_conn = db_pool.get().await?;
let rolling_stock_name = rolling_stock_form.common.name.clone();
let rolling_stock_name = rolling_stock_form.name.clone();
let rolling_stock_changeset: Changeset<RollingStockModel> = rolling_stock_form.into();

let rolling_stock = rolling_stock_changeset
Expand Down Expand Up @@ -247,7 +247,7 @@ async fn update(
let existing_rs_version = existing_rs.version;
assert_rolling_stock_unlocked(existing_rs.clone())?;

let rolling_stock_name = rolling_stock_form.common.name.clone();
let rolling_stock_name = rolling_stock_form.name.clone();

let existing_rs_form: RollingStockForm = existing_rs.into();

Expand Down Expand Up @@ -606,7 +606,7 @@ pub mod tests {

// THEN
let response_body: RollingStock = assert_status_and_read!(response, StatusCode::OK);
assert_eq!(response_body.common.name, name);
assert_eq!(response_body.name, name);
}

#[rstest]
Expand Down Expand Up @@ -644,27 +644,27 @@ pub mod tests {

let response_body = RollingStockModel::changeset()
.railjson_version(response_body.railjson_version)
.name(response_body.common.name)
.effort_curves(response_body.common.effort_curves)
.name(response_body.name)
.effort_curves(response_body.effort_curves)
.metadata(response_body.metadata)
.length(response_body.common.length)
.max_speed(response_body.common.max_speed)
.startup_time(response_body.common.startup_time)
.startup_acceleration(response_body.common.startup_acceleration)
.comfort_acceleration(response_body.common.comfort_acceleration)
.gamma(response_body.common.gamma)
.inertia_coefficient(response_body.common.inertia_coefficient)
.base_power_class(response_body.common.base_power_class)
.mass(response_body.common.mass)
.rolling_resistance(response_body.common.rolling_resistance)
.loading_gauge(response_body.common.loading_gauge)
.power_restrictions(response_body.common.power_restrictions)
.energy_sources(response_body.common.energy_sources)
.electrical_power_startup_time(response_body.common.electrical_power_startup_time)
.raise_pantograph_time(response_body.common.raise_pantograph_time)
.supported_signaling_systems(response_body.common.supported_signaling_systems);

assert_eq!(response_body.name, Some(rolling_stock_form.common.name));
.length(response_body.length)
.max_speed(response_body.max_speed)
.startup_time(response_body.startup_time)
.startup_acceleration(response_body.startup_acceleration)
.comfort_acceleration(response_body.comfort_acceleration)
.gamma(response_body.gamma)
.inertia_coefficient(response_body.inertia_coefficient)
.base_power_class(response_body.base_power_class)
.mass(response_body.mass)
.rolling_resistance(response_body.rolling_resistance)
.loading_gauge(response_body.loading_gauge)
.power_restrictions(response_body.power_restrictions)
.energy_sources(response_body.energy_sources)
.electrical_power_startup_time(response_body.electrical_power_startup_time)
.raise_pantograph_time(response_body.raise_pantograph_time)
.supported_signaling_systems(response_body.supported_signaling_systems);

assert_eq!(response_body.name, Some(rolling_stock_form.name));

// Check rolling_stock deletion
let delete_request = rolling_stock_delete_request(rolling_stock_id);
Expand Down Expand Up @@ -704,7 +704,7 @@ pub mod tests {
let mut rolling_stock_form = get_fast_rolling_stock_form(
"fast_rolling_stock_create_rolling_stock_with_base_power_class_empty",
);
rolling_stock_form.common.base_power_class = Some("".to_string());
rolling_stock_form.base_power_class = Some("".to_string());

// WHEN
let post_response = call_service(
Expand All @@ -727,7 +727,7 @@ pub mod tests {
let fast_rolling_stock = named_fast_rolling_stock(name, db_pool.clone()).await;
let app = create_test_service().await;
let mut rolling_stock_form = get_fast_rolling_stock_form(name);
rolling_stock_form.common.name = fast_rolling_stock.model.name.clone();
rolling_stock_form.name = fast_rolling_stock.model.name.clone();

// WHEN
let post_response = call_service(
Expand Down Expand Up @@ -859,7 +859,7 @@ pub mod tests {
let rolling_stock_id = fast_rolling_stock.id();

let mut rolling_stock_form: RollingStockForm = fast_rolling_stock.model.clone().into();
rolling_stock_form.common.name =
rolling_stock_form.name =
"other_rolling_stock_update_unlocked_rolling_stock".to_string();

// WHEN
Expand Down
Loading

0 comments on commit 038f823

Please sign in to comment.