Skip to content

Commit 9c61a08

Browse files
committed
editoast: move each function into the appropriate file
1 parent d8e1a81 commit 9c61a08

File tree

5 files changed

+53
-44
lines changed

5 files changed

+53
-44
lines changed

editoast/src/modelsv2/rolling_stock_model.rs

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
mod power_restriction;
2-
pub mod train_schedule_scenario_study_project;
1+
mod power_restrictions;
2+
mod rolling_stock_usage;
33

44
use std::collections::HashMap;
55

6-
use diesel::sql_query;
7-
use diesel::sql_types::BigInt;
86
use diesel::ExpressionMethods;
97
use diesel::QueryDsl;
108
use diesel::SelectableHelper;
@@ -18,11 +16,11 @@ use editoast_schemas::rolling_stock::RollingResistance;
1816
use editoast_schemas::rolling_stock::RollingStock;
1917
use editoast_schemas::rolling_stock::RollingStockMetadata;
2018
use editoast_schemas::rolling_stock::RollingStockSupportedSignalingSystems;
21-
use power_restriction::PowerRestriction;
19+
use power_restrictions::PowerRestriction;
20+
pub use rolling_stock_usage::TrainScheduleScenarioStudyProject;
2221
use serde::Deserialize;
2322
use serde::Serialize;
2423
use std::sync::Arc;
25-
use train_schedule_scenario_study_project::TrainScheduleScenarioStudyProject;
2624
use utoipa::ToSchema;
2725
use validator::Validate;
2826
use validator::ValidationError;
@@ -31,7 +29,6 @@ use validator::ValidationErrors;
3129
use crate::error::Result;
3230
use crate::modelsv2::prelude::*;
3331
use crate::modelsv2::rolling_stock_livery::RollingStockLiveryMetadataModel;
34-
use crate::modelsv2::DbConnection;
3532
use crate::modelsv2::DbConnectionPool;
3633
use crate::views::rolling_stocks::RollingStockWithLiveries;
3734

@@ -118,28 +115,6 @@ impl RollingStockModel {
118115
.map(|(key, _)| key.clone())
119116
.collect()
120117
}
121-
122-
pub async fn get_power_restrictions(conn: &mut DbConnection) -> Result<Vec<PowerRestriction>> {
123-
let power_restrictions = sql_query(include_str!(
124-
"rolling_stock_model/sql/get_power_restrictions.sql"
125-
))
126-
.load::<PowerRestriction>(conn)
127-
.await?;
128-
Ok(power_restrictions)
129-
}
130-
131-
pub async fn get_rolling_stock_usage(
132-
&self,
133-
conn: &mut DbConnection,
134-
) -> Result<Vec<TrainScheduleScenarioStudyProject>> {
135-
let result = sql_query(include_str!(
136-
"rolling_stock_model/sql/get_train_schedules_with_scenario.sql"
137-
))
138-
.bind::<BigInt, _>(self.id)
139-
.load::<TrainScheduleScenarioStudyProject>(conn)
140-
.await?;
141-
Ok(result)
142-
}
143118
}
144119

145120
impl RollingStockModelChangeset {

editoast/src/modelsv2/rolling_stock_model/power_restriction.rs

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use diesel::sql_query;
2+
use diesel::sql_types::Text;
3+
use diesel_async::RunQueryDsl;
4+
use serde::Deserialize;
5+
use serde::Serialize;
6+
use utoipa::ToSchema;
7+
8+
use super::RollingStockModel;
9+
use crate::error::Result;
10+
use crate::modelsv2::DbConnection;
11+
12+
editoast_common::schemas! {
13+
PowerRestriction,
14+
}
15+
16+
#[derive(QueryableByName, Debug, Clone, Serialize, Deserialize, ToSchema)]
17+
pub struct PowerRestriction {
18+
#[diesel(sql_type = Text)]
19+
pub power_restriction: String,
20+
}
21+
22+
impl RollingStockModel {
23+
pub async fn get_power_restrictions(conn: &mut DbConnection) -> Result<Vec<PowerRestriction>> {
24+
let power_restrictions = sql_query(include_str!("sql/get_power_restrictions.sql"))
25+
.load::<PowerRestriction>(conn)
26+
.await?;
27+
Ok(power_restrictions)
28+
}
29+
}

editoast/src/modelsv2/rolling_stock_model/train_schedule_scenario_study_project.rs editoast/src/modelsv2/rolling_stock_model/rolling_stock_usage.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
use diesel::sql_query;
12
use diesel::sql_types::BigInt;
23
use diesel::sql_types::Text;
4+
use diesel_async::RunQueryDsl;
35
use serde::Deserialize;
46
use serde::Serialize;
57
use utoipa::ToSchema;
68

9+
use super::RollingStockModel;
10+
use crate::error::Result;
11+
use crate::modelsv2::DbConnection;
12+
713
editoast_common::schemas! {
814
TrainScheduleScenarioStudyProject,
915
}
@@ -27,3 +33,16 @@ pub struct TrainScheduleScenarioStudyProject {
2733
#[diesel(sql_type = Text)]
2834
pub scenario_name: String,
2935
}
36+
37+
impl RollingStockModel {
38+
pub async fn get_rolling_stock_usage(
39+
&self,
40+
conn: &mut DbConnection,
41+
) -> Result<Vec<TrainScheduleScenarioStudyProject>> {
42+
let result = sql_query(include_str!("sql/get_train_schedules_with_scenario.sql"))
43+
.bind::<BigInt, _>(self.id)
44+
.load::<TrainScheduleScenarioStudyProject>(conn)
45+
.await?;
46+
Ok(result)
47+
}
48+
}

editoast/src/views/rolling_stocks/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::error::InternalError;
3939
use crate::error::Result;
4040
use crate::modelsv2::prelude::*;
4141
use crate::modelsv2::rolling_stock_livery::RollingStockLiveryModel;
42-
use crate::modelsv2::rolling_stock_model::train_schedule_scenario_study_project::TrainScheduleScenarioStudyProject;
42+
use crate::modelsv2::rolling_stock_model::TrainScheduleScenarioStudyProject;
4343
use crate::modelsv2::DbConnectionPool;
4444
use crate::modelsv2::Document;
4545
use crate::modelsv2::RollingStockModel;

0 commit comments

Comments
 (0)