Skip to content

Commit 2cca888

Browse files
Wadjetztheocrsb
authored andcommitted
editoast: adapt etcs braking curves endpoint (#15796)
Part of #15202 This PR adapt the `/train_schedules/{id}/etcs_braking_curves` to use the new exception table Rename the query string to `exception_id` Fix frontend > [!NOTE] > This PR targets a feature branch and may contain all its commits, as it has not been rebased yet. Only the last commit need to be reviewed. Signed-off-by: Egor <egor@berezify.fr>
1 parent 933395f commit 2cca888

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

editoast/openapi.yaml

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editoast/src/views/timetable/paced_train.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use core_client::simulation::PhysicsConsist;
1818
use database::DbConnection;
1919
use database::DbConnectionPoolV2;
2020
use editoast_derive::EditoastError;
21+
use editoast_models::TrainScheduleException;
2122
use editoast_models::prelude::*;
2223
use editoast_models::round_trips::TrainScheduleRoundTrips;
2324
use 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

front/src/applications/operationalStudies/hooks/useEtcsBrakingCurves.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const useEtcsBrakingCurves = (
8282
id: selectedTrainId,
8383
infraId,
8484
electricalProfileSetId,
85-
exceptionKey: exception?.key,
85+
exceptionId: exception?.id ?? undefined,
8686
}).unwrap();
8787
setEtcsBrakingCurves(formatEtcsCurves(data));
8888
} else {

front/src/common/api/generatedEditoastApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ const injectedRtkApi = api
13271327
params: {
13281328
infra_id: queryArg.infraId,
13291329
electrical_profile_set_id: queryArg.electricalProfileSetId,
1330-
exception_key: queryArg.exceptionKey,
1330+
exception_id: queryArg.exceptionId,
13311331
},
13321332
}),
13331333
providesTags: ['paced_train', 'etcs_braking_curves'],
@@ -2618,7 +2618,7 @@ export type GetTrainSchedulesByIdEtcsBrakingCurvesApiArg = {
26182618
id: number;
26192619
infraId: number;
26202620
electricalProfileSetId?: number;
2621-
exceptionKey?: string;
2621+
exceptionId?: number;
26222622
};
26232623
export type GetTrainSchedulesByIdPathApiResponse = /** status 200 The path */ PathfindingResult;
26242624
export type GetTrainSchedulesByIdPathApiArg = {

front/src/common/api/osrdEditoastApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ const osrdEditoastApi = generatedEditoastApi
123123
}),
124124
getEtcsBrakingCurves: builder.query<
125125
CoreEtcsBrakingCurvesResponse,
126-
{ id: TrainId; infraId: number; electricalProfileSetId?: number; exceptionKey?: string }
126+
{ id: TrainId; infraId: number; electricalProfileSetId?: number; exceptionId?: number }
127127
>({
128128
queryFn: async (
129-
{ id: trainId, infraId, electricalProfileSetId, exceptionKey },
129+
{ id: trainId, infraId, electricalProfileSetId, exceptionId },
130130
{ dispatch }
131131
) => {
132132
const pacedTrainId = isOccurrenceId(trainId)
@@ -138,7 +138,7 @@ const osrdEditoastApi = generatedEditoastApi
138138
id: extractEditoastIdFromPacedTrainId(pacedTrainId),
139139
infraId,
140140
electricalProfileSetId,
141-
exceptionKey,
141+
exceptionId,
142142
},
143143
{ subscribe: false }
144144
)

0 commit comments

Comments
 (0)