@@ -18,6 +18,7 @@ use core_client::simulation::PhysicsConsist;
1818use database:: DbConnection ;
1919use database:: DbConnectionPoolV2 ;
2020use editoast_derive:: EditoastError ;
21+ use editoast_models:: TrainScheduleException ;
2122use editoast_models:: prelude:: * ;
2223use editoast_models:: round_trips:: TrainScheduleRoundTrips ;
2324use itertools:: Itertools ;
@@ -400,6 +401,12 @@ pub(in crate::views) struct ExceptionQueryParam {
400401 exception_key : Option < String > ,
401402}
402403
404+ #[ derive( Debug , Default , Clone , Serialize , Deserialize , IntoParams , ToSchema ) ]
405+ #[ into_params( parameter_in = Query ) ]
406+ pub ( in crate :: views) struct TrainScheduleExceptionQueryParam {
407+ exception_id : Option < i64 > ,
408+ }
409+
403410/// Get a path from a paced train given an infrastructure id and a paced train id
404411#[ editoast_derive:: route]
405412#[ utoipa:: path(
@@ -583,7 +590,7 @@ pub(in crate::views) async fn simulation(
583590#[ utoipa:: path(
584591 get, path = "" ,
585592 tags = [ "paced_train" , "etcs_braking_curves" ] ,
586- params( TrainScheduleIdParam , InfraIdQueryParam , ElectricalProfileSetIdQueryParam , ExceptionQueryParam ) ,
593+ params( TrainScheduleIdParam , InfraIdQueryParam , ElectricalProfileSetIdQueryParam , TrainScheduleExceptionQueryParam ) ,
587594 responses(
588595 ( status = 200 , description = "ETCS Braking Curves Output" , body = core_client:: etcs_braking_curves:: Response ) ,
589596 ) ,
@@ -604,7 +611,9 @@ pub(in crate::views) async fn etcs_braking_curves(
604611 Query ( ElectricalProfileSetIdQueryParam {
605612 electrical_profile_set_id,
606613 } ) : Query < ElectricalProfileSetIdQueryParam > ,
607- Query ( ExceptionQueryParam { exception_key } ) : Query < ExceptionQueryParam > ,
614+ Query ( TrainScheduleExceptionQueryParam { exception_id } ) : Query <
615+ TrainScheduleExceptionQueryParam ,
616+ > ,
608617) -> Result < Json < core_client:: etcs_braking_curves:: Response > > {
609618 let authorized = auth
610619 . check_roles ( [ authz:: Role :: OperationalStudies , authz:: Role :: Stdcm ] . into ( ) )
@@ -635,17 +644,19 @@ pub(in crate::views) async fn etcs_braking_curves(
635644 } )
636645 . await ?;
637646
638- let train_schedule = match exception_key {
639- Some ( exception_key) => {
640- let exception = train_schedule
641- . exceptions
642- . iter ( )
643- . find ( |e| e. key == exception_key)
644- . ok_or_else ( || TrainScheduleError :: ExceptionNotFound {
645- exception_key : exception_key. clone ( ) ,
646- } ) ?;
647-
648- train_schedule. apply_exception ( exception)
647+ let train_occurrence = match exception_id {
648+ Some ( exception_id) => {
649+ let exception: schemas:: TrainScheduleException =
650+ TrainScheduleException :: retrieve_or_fail (
651+ db_pool. get ( ) . await ?,
652+ exception_id,
653+ || TrainScheduleError :: ExceptionNotFound {
654+ exception_key : exception_id. to_string ( ) ,
655+ } ,
656+ )
657+ . await ?
658+ . into ( ) ;
659+ train_schedule. apply_train_schedule_exception ( & exception)
649660 }
650661 None => train_schedule. into_train_occurrence ( ) ,
651662 } ;
@@ -655,7 +666,7 @@ pub(in crate::views) async fn etcs_braking_curves(
655666 & mut db_pool. get ( ) . await ?,
656667 valkey_client,
657668 core_client. clone ( ) ,
658- std:: slice:: from_ref ( & train_schedule ) ,
669+ std:: slice:: from_ref ( & train_occurrence ) ,
659670 & infra,
660671 electrical_profile_set_id,
661672 config. app_version . as_deref ( ) ,
@@ -683,9 +694,9 @@ pub(in crate::views) async fn etcs_braking_curves(
683694 // Build physics consist
684695 let rs = RollingStock :: retrieve_or_fail (
685696 db_pool. get ( ) . await ?,
686- train_schedule . rolling_stock_name . clone ( ) ,
697+ train_occurrence . rolling_stock_name . clone ( ) ,
687698 || TrainScheduleError :: RollingStockNotFound {
688- rolling_stock_name : train_schedule . rolling_stock_name . clone ( ) ,
699+ rolling_stock_name : train_occurrence . rolling_stock_name . clone ( ) ,
689700 } ,
690701 )
691702 . await ?;
@@ -694,25 +705,25 @@ pub(in crate::views) async fn etcs_braking_curves(
694705
695706 // Build schedule items and power restrictions
696707 let path_items_to_position = build_path_items_to_position (
697- & train_schedule . path ,
708+ & train_occurrence . path ,
698709 & pathfinding_response. path_item_positions ,
699710 ) ;
700- let schedule = build_sim_schedule_items ( & train_schedule . schedule , & path_items_to_position) ;
711+ let schedule = build_sim_schedule_items ( & train_occurrence . schedule , & path_items_to_position) ;
701712 let power_restrictions = build_sim_power_restriction_items (
702- & train_schedule . power_restrictions ,
713+ & train_occurrence . power_restrictions ,
703714 & path_items_to_position,
704715 ) ;
705716
706717 let etcs_braking_curves_request = core_client:: etcs_braking_curves:: Request {
707718 infra : infra. id ,
708719 expected_version : infra. version ,
709720 physics_consist,
710- comfort : train_schedule . comfort ,
721+ comfort : train_occurrence . comfort ,
711722 path : pathfinding_response. path ,
712723 schedule,
713724 power_restrictions,
714725 electrical_profile_set_id,
715- use_electrical_profiles : train_schedule . options . use_electrical_profiles ,
726+ use_electrical_profiles : train_occurrence . options . use_electrical_profiles ,
716727 mrsp,
717728 } ;
718729
0 commit comments