@@ -18,10 +18,6 @@ use actix_web::web::Json;
18
18
use actix_web:: web:: Path ;
19
19
use actix_web:: web:: Query ;
20
20
use actix_web:: HttpResponse ;
21
- use diesel:: sql_query;
22
- use diesel:: sql_types:: BigInt ;
23
- use diesel:: sql_types:: Text as SqlText ;
24
- use diesel_async:: RunQueryDsl ;
25
21
use editoast_derive:: EditoastError ;
26
22
use editoast_schemas:: rolling_stock:: RollingStockLivery ;
27
23
use editoast_schemas:: rolling_stock:: RollingStockLiveryMetadata ;
@@ -43,6 +39,7 @@ use crate::error::InternalError;
43
39
use crate :: error:: Result ;
44
40
use crate :: modelsv2:: prelude:: * ;
45
41
use crate :: modelsv2:: rolling_stock_livery:: RollingStockLiveryModel ;
42
+ use crate :: modelsv2:: rolling_stock_model:: train_schedule_scenario_study_project:: TrainScheduleScenarioStudyProject ;
46
43
use crate :: modelsv2:: DbConnectionPool ;
47
44
use crate :: modelsv2:: Document ;
48
45
use crate :: modelsv2:: RollingStockModel ;
@@ -78,7 +75,6 @@ editoast_common::schemas! {
78
75
RollingStockLiveryCreateForm ,
79
76
RollingStockError ,
80
77
RollingStockKey ,
81
- TrainScheduleScenarioStudyProject ,
82
78
RollingStockWithLiveries ,
83
79
light_rolling_stock:: schemas( ) ,
84
80
}
@@ -397,38 +393,21 @@ struct RollingStockLiveryCreateForm {
397
393
pub images : Vec < TempFile > ,
398
394
}
399
395
400
- #[ derive( Debug , QueryableByName , Serialize , Deserialize , PartialEq , ToSchema ) ]
401
- pub struct TrainScheduleScenarioStudyProject {
402
- #[ diesel( sql_type = BigInt ) ]
403
- pub train_schedule_id : i64 ,
404
- #[ diesel( sql_type = SqlText ) ]
405
- pub train_name : String ,
406
- #[ diesel( sql_type = BigInt ) ]
407
- pub project_id : i64 ,
408
- #[ diesel( sql_type = SqlText ) ]
409
- pub project_name : String ,
410
- #[ diesel( sql_type = BigInt ) ]
411
- pub study_id : i64 ,
412
- #[ diesel( sql_type = SqlText ) ]
413
- pub study_name : String ,
414
- #[ diesel( sql_type = BigInt ) ]
415
- pub scenario_id : i64 ,
416
- #[ diesel( sql_type = SqlText ) ]
417
- pub scenario_name : String ,
418
- }
419
-
420
396
async fn get_rolling_stock_usage (
421
397
db_pool : Data < DbConnectionPool > ,
422
398
rolling_stock_id : i64 ,
423
399
) -> Result < Vec < TrainScheduleScenarioStudyProject > > {
424
- let mut db_conn = db_pool. get ( ) . await ?;
425
- RollingStockModel :: exists ( & mut db_conn, rolling_stock_id) . await ?;
400
+ let conn = & mut db_pool. get ( ) . await ?;
401
+ // RollingStockModel::exists(&mut db_conn, rolling_stock_id).await?;
426
402
427
- sql_query ( include_str ! ( "sql/get_train_schedules_with_scenario.sql" ) )
428
- . bind :: < BigInt , _ > ( rolling_stock_id)
429
- . load ( & mut db_conn)
430
- . await
431
- . map_err ( |e| e. into ( ) )
403
+ let rolling_stock = RollingStockModel :: retrieve_or_fail ( conn, rolling_stock_id, || {
404
+ RollingStockError :: KeyNotFound {
405
+ rolling_stock_key : RollingStockKey :: Id ( rolling_stock_id) ,
406
+ }
407
+ } )
408
+ . await ?;
409
+
410
+ rolling_stock. get_rolling_stock_usage ( conn) . await
432
411
}
433
412
434
413
/// Create a rolling stock livery
0 commit comments