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 31ef244
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 191 deletions.
34 changes: 28 additions & 6 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 @@ -65,8 +62,33 @@ pub const ROLLING_STOCK_RAILJSON_VERSION: &str = "3.2";
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
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.

141 changes: 103 additions & 38 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5111,33 +5111,6 @@ components:
- C
type: object
RollingStock:
allOf:
- $ref: '#/components/schemas/RollingStockCommon'
- properties:
id:
format: int64
type: integer
locked:
description: Whether the rolling stock can be edited/deleted or not.
type: boolean
metadata:
$ref: '#/components/schemas/RollingStockMetadata'
railjson_version:
type: string
required:
- id
- railjson_version
- locked
- metadata
type: object
RollingStockComfortType:
description: Train comfort that will be used for the simulation
enum:
- STANDARD
- AC
- HEATING
type: string
RollingStockCommon:
properties:
base_power_class:
example: '5'
Expand All @@ -5160,6 +5133,9 @@ components:
type: array
gamma:
$ref: '#/components/schemas/Gamma'
id:
format: int64
type: integer
inertia_coefficient:
format: double
type: number
Expand All @@ -5168,19 +5144,26 @@ components:
type: number
loading_gauge:
$ref: '#/components/schemas/LoadingGaugeType'
locked:
description: Whether the rolling stock can be edited/deleted or not.
type: boolean
mass:
format: double
type: number
max_speed:
format: double
type: number
metadata:
$ref: '#/components/schemas/RollingStockMetadata'
name:
type: string
power_restrictions:
additionalProperties:
type: string
description: Mapping of power restriction code to power class
type: object
railjson_version:
type: string
raise_pantograph_time:
description: The time it takes to raise this train's pantograph in seconds. Is null if the train is not electric.
example: 15.0
Expand All @@ -5198,6 +5181,7 @@ components:
supported_signaling_systems:
$ref: '#/components/schemas/RollingStockSupportedSignalingSystems'
required:
- id
- name
- effort_curves
- base_power_class
Expand All @@ -5213,7 +5197,17 @@ components:
- loading_gauge
- power_restrictions
- supported_signaling_systems
- railjson_version
- locked
- metadata
type: object
RollingStockComfortType:
description: Train comfort that will be used for the simulation
enum:
- STANDARD
- AC
- HEATING
type: string
RollingStockError:
oneOf:
- enum:
Expand Down Expand Up @@ -5278,17 +5272,88 @@ components:
- BasePowerClassEmpty
type: string
RollingStockForm:
allOf:
- $ref: '#/components/schemas/RollingStockCommon'
- properties:
locked:
nullable: true
type: boolean
metadata:
$ref: '#/components/schemas/RollingStockMetadata'
required:
- metadata
type: object
properties:
base_power_class:
example: '5'
nullable: true
type: string
comfort_acceleration:
format: double
type: number
effort_curves:
$ref: '#/components/schemas/EffortCurves'
electrical_power_startup_time:
description: The time the train takes before actually using electrical power (in seconds). Is null if the train is not electric.
example: 5.0
format: double
nullable: true
type: number
energy_sources:
items:
$ref: '#/components/schemas/EnergySource'
type: array
gamma:
$ref: '#/components/schemas/Gamma'
inertia_coefficient:
format: double
type: number
length:
format: double
type: number
loading_gauge:
$ref: '#/components/schemas/LoadingGaugeType'
locked:
nullable: true
type: boolean
mass:
format: double
type: number
max_speed:
format: double
type: number
metadata:
$ref: '#/components/schemas/RollingStockMetadata'
name:
type: string
power_restrictions:
additionalProperties:
type: string
description: Mapping of power restriction code to power class
type: object
raise_pantograph_time:
description: The time it takes to raise this train's pantograph in seconds. Is null if the train is not electric.
example: 15.0
format: double
nullable: true
type: number
rolling_resistance:
$ref: '#/components/schemas/RollingResistance'
startup_acceleration:
format: double
type: number
startup_time:
format: double
type: number
supported_signaling_systems:
$ref: '#/components/schemas/RollingStockSupportedSignalingSystems'
required:
- name
- effort_curves
- base_power_class
- length
- max_speed
- startup_time
- startup_acceleration
- comfort_acceleration
- gamma
- inertia_coefficient
- mass
- rolling_resistance
- loading_gauge
- power_restrictions
- supported_signaling_systems
- metadata
type: object
RollingStockLivery:
properties:
compound_image_id:
Expand Down
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
Loading

0 comments on commit 31ef244

Please sign in to comment.