-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathrolling_stock_usage.rs
48 lines (44 loc) · 1.33 KB
/
rolling_stock_usage.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use diesel::sql_query;
use diesel::sql_types::BigInt;
use diesel::sql_types::Text;
use diesel_async::RunQueryDsl;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;
use super::RollingStockModel;
use crate::error::Result;
use crate::modelsv2::DbConnection;
editoast_common::schemas! {
TrainScheduleScenarioStudyProject,
}
#[derive(Debug, QueryableByName, Serialize, Deserialize, PartialEq, ToSchema)]
pub struct TrainScheduleScenarioStudyProject {
#[diesel(sql_type = BigInt)]
pub train_schedule_id: i64,
#[diesel(sql_type = Text)]
pub train_name: String,
#[diesel(sql_type = BigInt)]
pub project_id: i64,
#[diesel(sql_type = Text)]
pub project_name: String,
#[diesel(sql_type = BigInt)]
pub study_id: i64,
#[diesel(sql_type = Text)]
pub study_name: String,
#[diesel(sql_type = BigInt)]
pub scenario_id: i64,
#[diesel(sql_type = Text)]
pub scenario_name: String,
}
impl RollingStockModel {
pub async fn get_rolling_stock_usage(
&self,
conn: &mut DbConnection,
) -> Result<Vec<TrainScheduleScenarioStudyProject>> {
let result = sql_query(include_str!("sql/get_train_schedules_with_scenario.sql"))
.bind::<BigInt, _>(self.id)
.load::<TrainScheduleScenarioStudyProject>(conn)
.await?;
Ok(result)
}
}