diff --git a/editoast/src/views/electrical_profiles.rs b/editoast/src/views/electrical_profiles.rs index 00cb45b1e09..817dce04098 100644 --- a/editoast/src/views/electrical_profiles.rs +++ b/editoast/src/views/electrical_profiles.rs @@ -194,7 +194,7 @@ async fn post_electrical_profile( State(db_pool): State, Extension(authorizer): AuthorizerExt, Query(ep_set_name): Query, - Json(data): Json, + Json(ep_data): Json, ) -> Result> { let authorized = authorizer .check_roles([BuiltinRole::InfraWrite].into()) @@ -205,7 +205,7 @@ async fn post_electrical_profile( } let ep_set = ElectricalProfileSet::changeset() .name(ep_set_name.name) - .data(data); + .data(ep_data); let conn = &mut db_pool.get().await?; Ok(Json(ep_set.create(conn).await?)) } diff --git a/editoast/src/views/infra/mod.rs b/editoast/src/views/infra/mod.rs index f1dd561cce0..eb002fea86d 100644 --- a/editoast/src/views/infra/mod.rs +++ b/editoast/src/views/infra/mod.rs @@ -335,7 +335,7 @@ impl From for Changeset { async fn create( db_pool: State, Extension(authorizer): AuthorizerExt, - Json(data): Json, + Json(infra_form): Json, ) -> Result { let authorized = authorizer .check_roles([BuiltinRole::InfraWrite].into()) @@ -345,7 +345,7 @@ async fn create( return Err(AuthorizationError::Unauthorized.into()); } - let infra: Changeset = data.into(); + let infra: Changeset = infra_form.into(); let infra = infra.create(db_pool.get().await?.deref_mut()).await?; Ok((StatusCode::CREATED, Json(infra))) } diff --git a/editoast/src/views/v2/timetable.rs b/editoast/src/views/v2/timetable.rs index aedd8c3db7b..b5a87917bc5 100644 --- a/editoast/src/views/v2/timetable.rs +++ b/editoast/src/views/v2/timetable.rs @@ -219,7 +219,7 @@ async fn train_schedule( db_pool: State, Extension(authorizer): AuthorizerExt, Path(timetable_id): Path, - Json(data): Json>, + Json(train_schedules): Json>, ) -> Result>> { let authorized = authorizer .check_roles([BuiltinRole::TimetableWrite].into()) @@ -237,7 +237,7 @@ async fn train_schedule( }) .await?; - let changesets: Vec = data + let changesets: Vec = train_schedules .into_iter() .map(|ts| TrainScheduleForm { timetable_id: Some(timetable_id), diff --git a/editoast/src/views/v2/timetable/stdcm.rs b/editoast/src/views/v2/timetable/stdcm.rs index b20f5151a2e..1ab7aedc243 100644 --- a/editoast/src/views/v2/timetable/stdcm.rs +++ b/editoast/src/views/v2/timetable/stdcm.rs @@ -153,7 +153,7 @@ async fn stdcm( Extension(authorizer): AuthorizerExt, Path(id): Path, Query(query): Query, - Json(data): Json, + Json(stdcm_request): Json, ) -> Result> { let authorized = authorizer .check_roles([BuiltinRole::Stdcm].into()) @@ -188,9 +188,9 @@ async fn stdcm( let rolling_stock = RollingStockModel::retrieve_or_fail( db_pool.get().await?.deref_mut(), - data.rolling_stock_id, + stdcm_request.rolling_stock_id, || STDCMError::RollingStockNotFound { - rolling_stock_id: data.rolling_stock_id, + rolling_stock_id: stdcm_request.rolling_stock_id, }, ) .await?; @@ -201,7 +201,7 @@ async fn stdcm( core_client.clone(), &trains, &infra, - data.electrical_profile_set_id, + stdcm_request.electrical_profile_set_id, ) .await?; @@ -210,7 +210,7 @@ async fn stdcm( db_pool.clone(), redis_client.clone(), core_client.clone(), - &data, + &stdcm_request, &infra, &rolling_stock, timetable_id, @@ -224,17 +224,22 @@ async fn stdcm( })) } }; - let earliest_step_tolerance_window = get_earliest_step_tolerance_window(&data); - let maximum_departure_delay = - get_maximum_departure_delay(&data, simulation_run_time, earliest_step_tolerance_window); - let maximum_run_time_without_tolerance = 2 * simulation_run_time + get_total_stop_time(&data); + let earliest_step_tolerance_window = get_earliest_step_tolerance_window(&stdcm_request); + let maximum_departure_delay = get_maximum_departure_delay( + &stdcm_request, + simulation_run_time, + earliest_step_tolerance_window, + ); + let maximum_run_time_without_tolerance = + 2 * simulation_run_time + get_total_stop_time(&stdcm_request); let maximum_run_time = get_maximum_run_time( - &data, + &stdcm_request, maximum_run_time_without_tolerance, earliest_step_tolerance_window, ); - let departure_time = get_earliest_departure_time(&data, maximum_run_time_without_tolerance); + let departure_time = + get_earliest_departure_time(&stdcm_request, maximum_run_time_without_tolerance); let latest_simulation_end = departure_time + Duration::milliseconds((maximum_run_time) as i64); // 3. Get scheduled train requirements @@ -242,7 +247,8 @@ async fn stdcm( build_train_requirements(trains, simulations, departure_time, latest_simulation_end); // 4. Parse stdcm path items - let path_items = parse_stdcm_steps(db_pool.get().await?.deref_mut(), &data, &infra).await?; + let path_items = + parse_stdcm_steps(db_pool.get().await?.deref_mut(), &stdcm_request, &infra).await?; // 5. Build STDCM request let stdcm_response = STDCMRequest { @@ -253,18 +259,18 @@ async fn stdcm( rolling_stock_supported_signaling_systems: rolling_stock .supported_signaling_systems .clone(), - comfort: data.comfort, + comfort: stdcm_request.comfort, path_items, start_time: departure_time, trains_requirements, maximum_departure_delay, maximum_run_time, - speed_limit_tag: data.speed_limit_tags, - time_gap_before: data.time_gap_before, - time_gap_after: data.time_gap_after, - margin: data.margin, + speed_limit_tag: stdcm_request.speed_limit_tags, + time_gap_before: stdcm_request.time_gap_before, + time_gap_after: stdcm_request.time_gap_after, + margin: stdcm_request.margin, time_step: Some(2000), - work_schedules: match data.work_schedule_group_id { + work_schedules: match stdcm_request.work_schedule_group_id { Some(work_schedule_group_id) => { build_work_schedules( db_pool.get().await?.deref_mut(), diff --git a/editoast/src/views/v2/train_schedule.rs b/editoast/src/views/v2/train_schedule.rs index 03eedea2284..d01b9860c62 100644 --- a/editoast/src/views/v2/train_schedule.rs +++ b/editoast/src/views/v2/train_schedule.rs @@ -217,7 +217,7 @@ struct BatchRequest { async fn get_batch( app_state: State, Extension(authorizer): AuthorizerExt, - Json(data): Json, + Json(BatchRequest { ids: train_ids }): Json, ) -> Result>> { let authorized = authorizer .check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into()) @@ -229,7 +229,6 @@ async fn get_batch( let db_pool = app_state.db_pool_v2.clone(); let conn = &mut db_pool.get().await?; - let train_ids = data.ids; let train_schedules: Vec = TrainSchedule::retrieve_batch_or_fail(conn, train_ids, |missing| { TrainScheduleError::BatchTrainScheduleNotFound { @@ -252,7 +251,7 @@ async fn get_batch( async fn delete( app_state: State, Extension(authorizer): AuthorizerExt, - Json(data): Json, + Json(BatchRequest { ids: train_ids }): Json, ) -> Result { let authorized = authorizer .check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableWrite].into()) @@ -266,8 +265,7 @@ async fn delete( use crate::modelsv2::DeleteBatch; let conn = &mut db_pool.get().await?; - let train_schedule_ids = data.ids; - TrainSchedule::delete_batch_or_fail(conn, train_schedule_ids, |number| { + TrainSchedule::delete_batch_or_fail(conn, train_ids, |number| { TrainScheduleError::BatchTrainScheduleNotFound { number } }) .await?; @@ -289,7 +287,7 @@ async fn put( db_pool: State, Extension(authorizer): AuthorizerExt, train_schedule_id: Path, - Json(data): Json, + Json(train_schedule_form): Json, ) -> Result> { let authorized = authorizer .check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableWrite].into()) @@ -302,7 +300,7 @@ async fn put( let conn = &mut db_pool.get().await?; let train_schedule_id = train_schedule_id.id; - let ts_changeset: TrainScheduleChangeset = data.into(); + let ts_changeset: TrainScheduleChangeset = train_schedule_form.into(); let ts_result = ts_changeset .update_or_fail(conn, train_schedule_id, || TrainScheduleError::NotFound { @@ -672,7 +670,11 @@ enum SimulationSummaryResult { async fn simulation_summary( app_state: State, Extension(authorizer): AuthorizerExt, - Json(data): Json, + Json(SimulationBatchForm { + infra_id, + electrical_profile_set_id, + ids: train_schedule_ids, + }): Json, ) -> Result>> { let authorized = authorizer .check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into()) @@ -686,12 +688,6 @@ async fn simulation_summary( let redis_client = app_state.redis.clone(); let core = app_state.core_client.clone(); - let SimulationBatchForm { - infra_id, - electrical_profile_set_id, - ids: train_schedule_ids, - } = data; - let infra = Infra::retrieve_or_fail(db_pool.get().await?.deref_mut(), infra_id, || { TrainScheduleError::InfraNotFound { infra_id } }) diff --git a/editoast/src/views/v2/train_schedule/projection.rs b/editoast/src/views/v2/train_schedule/projection.rs index caa44bf6346..d4cc0cbed7c 100644 --- a/editoast/src/views/v2/train_schedule/projection.rs +++ b/editoast/src/views/v2/train_schedule/projection.rs @@ -128,7 +128,12 @@ struct CachedProjectPathTrainResult { async fn project_path( app_state: State, Extension(authorizer): AuthorizerExt, - Json(data): Json, + Json(ProjectPathForm { + infra_id, + ids: train_ids, + path, + electrical_profile_set_id, + }): Json, ) -> Result>> { let authorized = authorizer .check_roles( @@ -149,12 +154,6 @@ async fn project_path( let redis_client = app_state.redis.clone(); let core_client = app_state.core_client.clone(); - let ProjectPathForm { - infra_id, - ids: train_ids, - path, - electrical_profile_set_id, - } = data; let ProjectPathInput { track_section_ranges: path_track_ranges, routes: path_routes, diff --git a/editoast/src/views/work_schedules.rs b/editoast/src/views/work_schedules.rs index c54f4f5c9d0..bd26c9e6680 100644 --- a/editoast/src/views/work_schedules.rs +++ b/editoast/src/views/work_schedules.rs @@ -140,7 +140,10 @@ struct WorkScheduleCreateResponse { async fn create( State(app_state): State, Extension(authorizer): AuthorizerExt, - Json(data): Json, + Json(WorkScheduleCreateForm { + work_schedule_group_name, + work_schedules, + }): Json, ) -> Result> { let authorized = authorizer .check_roles([BuiltinRole::WorkScheduleWrite].into()) @@ -153,20 +156,17 @@ async fn create( let db_pool = app_state.db_pool_v2.clone(); let conn = &mut db_pool.get().await?; - let work_schedule_create_form = data; - // Create the work_schedule_group let work_schedule_group = WorkScheduleGroup::changeset() - .name(work_schedule_create_form.work_schedule_group_name.clone()) + .name(work_schedule_group_name.clone()) .creation_date(Utc::now().naive_utc()) .create(conn) .await; - let work_schedule_group = work_schedule_group - .map_err(|e| map_diesel_error(e, work_schedule_create_form.work_schedule_group_name))?; + let work_schedule_group = + work_schedule_group.map_err(|e| map_diesel_error(e, work_schedule_group_name))?; // Create work schedules - let work_schedules_changesets = work_schedule_create_form - .work_schedules + let work_schedules_changesets = work_schedules .into_iter() .map(|work_schedule| work_schedule.into_work_schedule_changeset(work_schedule_group.id)) .collect::>();