Skip to content

Commit

Permalink
editoast: refactor schemas declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Apr 10, 2024
1 parent 4e74e3c commit 91c21db
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,14 @@ use utoipa::ToSchema;

editoast_common::schemas! {
RollingStock,
Gamma,
ConditionalEffortCurve,
EffortCurve,
EffortCurves,
EffortCurveConditions,
ModeEffortCurves,
RollingStockComfortType,
RollingResistance,
EnergySource,
EnergyStorage,
RefillLaw,
SpeedDependantPower,
RollingStockSupportedSignalingSystems,
RollingStockMetadata,
LoadingGaugeType,
RollingStockLivery,
RollingStockLiveryMetadata,
gamma::schemas(),
effort_curves::schemas(),
energy_source::schemas(),
rolling_stock_livery::schemas(),
rolling_resistance::schemas(),
supported_signaling_systems::schemas(),
rolling_stock_metadata::schemas(),
loading_gauge_type::schemas(),
}

pub const ROLLING_STOCK_RAILJSON_VERSION: &str = "3.2";
Expand Down
9 changes: 9 additions & 0 deletions editoast/editoast_schemas/src/rolling_stock/effort_curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ use strum::Display;
use strum::EnumString;
use utoipa::ToSchema;

editoast_common::schemas! {
ConditionalEffortCurve,
EffortCurve,
EffortCurves,
EffortCurveConditions,
ModeEffortCurves,
RollingStockComfortType,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, ToSchema, Hash)]
#[serde(deny_unknown_fields)]
pub struct EffortCurves {
Expand Down
7 changes: 7 additions & 0 deletions editoast/editoast_schemas/src/rolling_stock/energy_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

editoast_common::schemas! {
EnergySource,
EnergyStorage,
RefillLaw,
SpeedDependantPower,
}

// Energy sources schema

/// energy source of a rolling stock
Expand Down
4 changes: 4 additions & 0 deletions editoast/editoast_schemas/src/rolling_stock/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

editoast_common::schemas! {
Gamma,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, ToSchema, Derivative)]
#[serde(deny_unknown_fields)]
#[derivative(Hash)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use serde::Serialize;
use strum::FromRepr;
use utoipa::ToSchema;

editoast_common::schemas! {
LoadingGaugeType,
}

#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, ToSchema, Hash, FromRepr)]
pub enum LoadingGaugeType {
G1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

editoast_common::schemas! {
RollingResistance,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, ToSchema, Derivative)]
#[derivative(Hash)]
#[serde(deny_unknown_fields)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

editoast_common::schemas! {
RollingStockLivery,
RollingStockLiveryMetadata,
}

#[derive(Debug, Deserialize, Serialize, ToSchema)]
pub struct RollingStockLivery {
pub id: i64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

editoast_common::schemas! {
RollingStockMetadata,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct RollingStockMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

editoast_common::schemas! {
RollingStockSupportedSignalingSystems,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct RollingStockSupportedSignalingSystems(pub Vec<String>);

Expand Down
1 change: 0 additions & 1 deletion editoast/src/schema/rolling_stock/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod light_rolling_stock;

editoast_common::schemas! {
RollingStockWithLiveries,
light_rolling_stock::schemas(),
}
25 changes: 1 addition & 24 deletions editoast/src/views/rolling_stocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ pub mod tests {
use crate::fixtures::tests::train_schedule_with_scenario;
use crate::models::rolling_stock::tests::get_invalid_effort_curves;
use crate::modelsv2::rolling_stock_model::RollingStockModel;
use crate::modelsv2::Model;
use crate::views::rolling_stocks::rolling_stock_form::RollingStockForm;
use crate::views::tests::create_test_service;
use crate::DbPool;
Expand Down Expand Up @@ -642,29 +641,7 @@ pub mod tests {
let response_body: RollingStock = assert_status_and_read!(post_response, StatusCode::OK);
let rolling_stock_id: i64 = response_body.id;

let response_body = RollingStockModel::changeset()
.railjson_version(response_body.railjson_version)
.name(response_body.name)
.effort_curves(response_body.effort_curves)
.metadata(response_body.metadata)
.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));
assert_eq!(response_body.name, rolling_stock_form.name);

// Check rolling_stock deletion
let delete_request = rolling_stock_delete_request(rolling_stock_id);
Expand Down

0 comments on commit 91c21db

Please sign in to comment.