Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ca5ea68
editoast: adapt get train schedules exceptions (#15502)
Wadjetz Mar 10, 2026
296af98
editoast: add apply_train_schedule_exception (#15688)
Wadjetz Mar 11, 2026
7fd64f2
front: use create exceptions endpoint for added exception
theocrsb Feb 24, 2026
d5ff515
front: create exception when train is duplicate
theocrsb Mar 4, 2026
9347356
front: invalidate rtk cache on exception creation
theocrsb Mar 11, 2026
cb4ce29
editoast: add occurrences utilities functions (#15741)
Wadjetz Mar 17, 2026
9137a6b
editoast: retrieve exceptions by ids and timetable utility function (…
Wadjetz Mar 19, 2026
55dcfad
editoast: adapt etcs braking curves endpoint (#15796)
Wadjetz Mar 20, 2026
956a834
front: adapt timetable import (#15604)
theocrsb Mar 23, 2026
5705065
editoast: adapt train schedule get path endpoint to use exceptions ta…
Wadjetz Mar 23, 2026
26d0ff9
editoast: adapt simulation endpoint with new exceptions (#15695)
Wadjetz Mar 24, 2026
848c38e
editoast: adapt conflicts endpoint (#15689)
Wadjetz Mar 24, 2026
baa3550
editost: adapt track_occupancy endpoint with new exceptions (#15793)
Wadjetz Mar 26, 2026
5dcbfdd
editoast: adapt paced train simulation summary (#15591)
Wadjetz Mar 26, 2026
039e50d
front: fix invalidatesTags error
younesschrifi Mar 28, 2026
91adfa5
editoast: adapt project path endpoint
younesschrifi Mar 17, 2026
7828b8a
editoast: fix editoast lint error
younesschrifi Mar 28, 2026
3860901
editoast: adapt level crossing occupancy endpoint with new exceptions…
Wadjetz Mar 30, 2026
ccadf09
editoast: adapt occupancy blocks endpoint (#15765)
Wadjetz Mar 30, 2026
68186fb
editoast: replace exception_key with excpetion_id
younesschrifi Mar 30, 2026
dc4343a
editoast: refactor train schedule exceptions fixtures (#16008)
Wadjetz Apr 2, 2026
c487619
editoast: adapt requirements endpoin to new exception model
younesschrifi Mar 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions editoast/editoast_models/src/train_schedule_exception.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use std::collections::HashMap;

use database::DbConnection;
use editoast_derive::Model;
use itertools::Itertools;
use schemas::paced_train::PacedTrainException;
use schemas::train_schedule_exception::TrainScheduleExceptionChangeGroups;

use crate as editoast_models;
use crate::prelude::List;
use crate::prelude::SelectionSettings;

#[derive(Debug, Clone, Model)]
#[cfg_attr(test, derive(serde::Deserialize))]
Expand All @@ -18,6 +25,33 @@ pub struct TrainScheduleException {
pub change_groups: TrainScheduleExceptionChangeGroups,
}

#[cfg(any(test, feature = "testing"))]
impl TrainScheduleException {
pub fn fixture_created(key: &str, occurrence_index: Option<i64>) -> Self {
Self {
id: 1,
disabled: false,
key: Some(key.into()),
occurrence_index,
timetable_id: 1,
train_schedule_id: 1,
change_groups: TrainScheduleExceptionChangeGroups::fixture_created(),
}
}

pub fn fixture_modified(key: &str, occurrence_index: i64) -> Self {
Self {
id: 1,
disabled: false,
key: Some(key.into()),
occurrence_index: Some(occurrence_index),
timetable_id: 1,
train_schedule_id: 1,
change_groups: TrainScheduleExceptionChangeGroups::fixture_modified(),
}
}
}

impl From<TrainScheduleException> for schemas::TrainScheduleException {
fn from(train_schedule_exception: TrainScheduleException) -> Self {
Self {
Expand All @@ -31,3 +65,52 @@ impl From<TrainScheduleException> for schemas::TrainScheduleException {
}
}
}

impl TrainScheduleException {
pub async fn retrieve_exceptions_by_train_schedules(
conn: &mut DbConnection,
timetable_id: i64,
train_schedules_ids: Vec<i64>,
) -> Result<Vec<TrainScheduleException>, editoast_models::Error> {
let train_schedules_ids_for_settings = train_schedules_ids.clone();
let exceptions_settings = SelectionSettings::new()
.filter(move || editoast_models::TrainScheduleException::TIMETABLE_ID.eq(timetable_id))
.filter(move || {
editoast_models::TrainScheduleException::TRAIN_SCHEDULE_ID
.eq_any(train_schedules_ids_for_settings.clone())
});

let mut exceptions_map: HashMap<i64, Vec<TrainScheduleException>> =
Self::list(conn, exceptions_settings)
.await?
.into_iter()
.into_group_map_by(|e| e.train_schedule_id);

let exceptions = train_schedules_ids
.into_iter()
.flat_map(|id| exceptions_map.remove(&id).unwrap_or_default())
.collect();

Ok(exceptions)
}
}

impl From<TrainScheduleException> for PacedTrainException {
fn from(train_schedule_exception: TrainScheduleException) -> Self {
let exception_type = match train_schedule_exception.occurrence_index {
Some(occurrence_index) => schemas::paced_train::ExceptionType::Modified {
occurrence_index: occurrence_index as usize,
},
None => schemas::paced_train::ExceptionType::Created {},
};
Self {
id: Some(train_schedule_exception.id),
key: train_schedule_exception
.key
.unwrap_or_else(|| train_schedule_exception.id.to_string()),
exception_type,
disabled: train_schedule_exception.disabled,
change_groups: train_schedule_exception.change_groups,
}
}
}
65 changes: 59 additions & 6 deletions editoast/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions editoast/schemas/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub fn rolling_stock_with_invalid_effort_curves_json() -> &'static str {

pub fn simple_created_exception_with_change_groups(key: &str) -> PacedTrainException {
PacedTrainException {
id: None,
key: key.into(),
exception_type: ExceptionType::Created {},
disabled: false,
Expand Down
2 changes: 2 additions & 0 deletions editoast/schemas/src/paced_train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ impl Serialize for TrainSchedule {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
#[cfg_attr(feature = "testing", derive(Default))]
pub struct PacedTrainException {
/// TODO The new exception table id (for incremental migration)
pub id: Option<i64>,
/// Unique key for the exception within the paced train, required and generated by the frontend.
pub key: String,
#[serde(flatten)]
Expand Down
Loading
Loading