Skip to content

Commit 9df24ea

Browse files
committed
editoast: improve naming of extracted variables in several handlers
1 parent 692d164 commit 9df24ea

File tree

7 files changed

+54
-53
lines changed

7 files changed

+54
-53
lines changed

editoast/src/views/electrical_profiles.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async fn post_electrical_profile(
194194
State(db_pool): State<DbConnectionPoolV2>,
195195
Extension(authorizer): AuthorizerExt,
196196
Query(ep_set_name): Query<ElectricalProfileQueryArgs>,
197-
Json(data): Json<ElectricalProfileSetData>,
197+
Json(ep_data): Json<ElectricalProfileSetData>,
198198
) -> Result<Json<ElectricalProfileSet>> {
199199
let authorized = authorizer
200200
.check_roles([BuiltinRole::InfraWrite].into())
@@ -205,7 +205,7 @@ async fn post_electrical_profile(
205205
}
206206
let ep_set = ElectricalProfileSet::changeset()
207207
.name(ep_set_name.name)
208-
.data(data);
208+
.data(ep_data);
209209
let conn = &mut db_pool.get().await?;
210210
Ok(Json(ep_set.create(conn).await?))
211211
}

editoast/src/views/infra/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl From<InfraCreateForm> for Changeset<Infra> {
335335
async fn create(
336336
db_pool: State<DbConnectionPoolV2>,
337337
Extension(authorizer): AuthorizerExt,
338-
Json(data): Json<InfraCreateForm>,
338+
Json(infra_form): Json<InfraCreateForm>,
339339
) -> Result<impl IntoResponse> {
340340
let authorized = authorizer
341341
.check_roles([BuiltinRole::InfraWrite].into())
@@ -345,7 +345,7 @@ async fn create(
345345
return Err(AuthorizationError::Unauthorized.into());
346346
}
347347

348-
let infra: Changeset<Infra> = data.into();
348+
let infra: Changeset<Infra> = infra_form.into();
349349
let infra = infra.create(db_pool.get().await?.deref_mut()).await?;
350350
Ok((StatusCode::CREATED, Json(infra)))
351351
}

editoast/src/views/v2/timetable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async fn train_schedule(
219219
db_pool: State<DbConnectionPoolV2>,
220220
Extension(authorizer): AuthorizerExt,
221221
Path(timetable_id): Path<TimetableIdParam>,
222-
Json(data): Json<Vec<TrainScheduleBase>>,
222+
Json(train_schedules): Json<Vec<TrainScheduleBase>>,
223223
) -> Result<Json<Vec<TrainScheduleResult>>> {
224224
let authorized = authorizer
225225
.check_roles([BuiltinRole::TimetableWrite].into())
@@ -237,7 +237,7 @@ async fn train_schedule(
237237
})
238238
.await?;
239239

240-
let changesets: Vec<TrainScheduleChangeset> = data
240+
let changesets: Vec<TrainScheduleChangeset> = train_schedules
241241
.into_iter()
242242
.map(|ts| TrainScheduleForm {
243243
timetable_id: Some(timetable_id),

editoast/src/views/v2/timetable/stdcm.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async fn stdcm(
153153
Extension(authorizer): AuthorizerExt,
154154
Path(id): Path<i64>,
155155
Query(query): Query<InfraIdQueryParam>,
156-
Json(data): Json<STDCMRequestPayload>,
156+
Json(stdcm_request): Json<STDCMRequestPayload>,
157157
) -> Result<Json<STDCMResponse>> {
158158
let authorized = authorizer
159159
.check_roles([BuiltinRole::Stdcm].into())
@@ -188,9 +188,9 @@ async fn stdcm(
188188

189189
let rolling_stock = RollingStockModel::retrieve_or_fail(
190190
db_pool.get().await?.deref_mut(),
191-
data.rolling_stock_id,
191+
stdcm_request.rolling_stock_id,
192192
|| STDCMError::RollingStockNotFound {
193-
rolling_stock_id: data.rolling_stock_id,
193+
rolling_stock_id: stdcm_request.rolling_stock_id,
194194
},
195195
)
196196
.await?;
@@ -201,7 +201,7 @@ async fn stdcm(
201201
core_client.clone(),
202202
&trains,
203203
&infra,
204-
data.electrical_profile_set_id,
204+
stdcm_request.electrical_profile_set_id,
205205
)
206206
.await?;
207207

@@ -210,7 +210,7 @@ async fn stdcm(
210210
db_pool.clone(),
211211
redis_client.clone(),
212212
core_client.clone(),
213-
&data,
213+
&stdcm_request,
214214
&infra,
215215
&rolling_stock,
216216
timetable_id,
@@ -224,25 +224,31 @@ async fn stdcm(
224224
}))
225225
}
226226
};
227-
let earliest_step_tolerance_window = get_earliest_step_tolerance_window(&data);
228-
let maximum_departure_delay =
229-
get_maximum_departure_delay(&data, simulation_run_time, earliest_step_tolerance_window);
230-
let maximum_run_time_without_tolerance = 2 * simulation_run_time + get_total_stop_time(&data);
227+
let earliest_step_tolerance_window = get_earliest_step_tolerance_window(&stdcm_request);
228+
let maximum_departure_delay = get_maximum_departure_delay(
229+
&stdcm_request,
230+
simulation_run_time,
231+
earliest_step_tolerance_window,
232+
);
233+
let maximum_run_time_without_tolerance =
234+
2 * simulation_run_time + get_total_stop_time(&stdcm_request);
231235
let maximum_run_time = get_maximum_run_time(
232-
&data,
236+
&stdcm_request,
233237
maximum_run_time_without_tolerance,
234238
earliest_step_tolerance_window,
235239
);
236240

237-
let departure_time = get_earliest_departure_time(&data, maximum_run_time_without_tolerance);
241+
let departure_time =
242+
get_earliest_departure_time(&stdcm_request, maximum_run_time_without_tolerance);
238243
let latest_simulation_end = departure_time + Duration::milliseconds((maximum_run_time) as i64);
239244

240245
// 3. Get scheduled train requirements
241246
let trains_requirements =
242247
build_train_requirements(trains, simulations, departure_time, latest_simulation_end);
243248

244249
// 4. Parse stdcm path items
245-
let path_items = parse_stdcm_steps(db_pool.get().await?.deref_mut(), &data, &infra).await?;
250+
let path_items =
251+
parse_stdcm_steps(db_pool.get().await?.deref_mut(), &stdcm_request, &infra).await?;
246252

247253
// 5. Build STDCM request
248254
let stdcm_response = STDCMRequest {
@@ -253,18 +259,18 @@ async fn stdcm(
253259
rolling_stock_supported_signaling_systems: rolling_stock
254260
.supported_signaling_systems
255261
.clone(),
256-
comfort: data.comfort,
262+
comfort: stdcm_request.comfort,
257263
path_items,
258264
start_time: departure_time,
259265
trains_requirements,
260266
maximum_departure_delay,
261267
maximum_run_time,
262-
speed_limit_tag: data.speed_limit_tags,
263-
time_gap_before: data.time_gap_before,
264-
time_gap_after: data.time_gap_after,
265-
margin: data.margin,
268+
speed_limit_tag: stdcm_request.speed_limit_tags,
269+
time_gap_before: stdcm_request.time_gap_before,
270+
time_gap_after: stdcm_request.time_gap_after,
271+
margin: stdcm_request.margin,
266272
time_step: Some(2000),
267-
work_schedules: match data.work_schedule_group_id {
273+
work_schedules: match stdcm_request.work_schedule_group_id {
268274
Some(work_schedule_group_id) => {
269275
build_work_schedules(
270276
db_pool.get().await?.deref_mut(),

editoast/src/views/v2/train_schedule.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ struct BatchRequest {
217217
async fn get_batch(
218218
app_state: State<AppState>,
219219
Extension(authorizer): AuthorizerExt,
220-
Json(data): Json<BatchRequest>,
220+
Json(BatchRequest { ids: train_ids }): Json<BatchRequest>,
221221
) -> Result<Json<Vec<TrainScheduleResult>>> {
222222
let authorized = authorizer
223223
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into())
@@ -229,7 +229,6 @@ async fn get_batch(
229229

230230
let db_pool = app_state.db_pool_v2.clone();
231231
let conn = &mut db_pool.get().await?;
232-
let train_ids = data.ids;
233232
let train_schedules: Vec<TrainSchedule> =
234233
TrainSchedule::retrieve_batch_or_fail(conn, train_ids, |missing| {
235234
TrainScheduleError::BatchTrainScheduleNotFound {
@@ -252,7 +251,7 @@ async fn get_batch(
252251
async fn delete(
253252
app_state: State<AppState>,
254253
Extension(authorizer): AuthorizerExt,
255-
Json(data): Json<BatchRequest>,
254+
Json(BatchRequest { ids: train_ids }): Json<BatchRequest>,
256255
) -> Result<impl IntoResponse> {
257256
let authorized = authorizer
258257
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableWrite].into())
@@ -266,8 +265,7 @@ async fn delete(
266265

267266
use crate::modelsv2::DeleteBatch;
268267
let conn = &mut db_pool.get().await?;
269-
let train_schedule_ids = data.ids;
270-
TrainSchedule::delete_batch_or_fail(conn, train_schedule_ids, |number| {
268+
TrainSchedule::delete_batch_or_fail(conn, train_ids, |number| {
271269
TrainScheduleError::BatchTrainScheduleNotFound { number }
272270
})
273271
.await?;
@@ -289,7 +287,7 @@ async fn put(
289287
db_pool: State<DbConnectionPoolV2>,
290288
Extension(authorizer): AuthorizerExt,
291289
train_schedule_id: Path<TrainScheduleIdParam>,
292-
Json(data): Json<TrainScheduleForm>,
290+
Json(train_schedule_form): Json<TrainScheduleForm>,
293291
) -> Result<Json<TrainScheduleResult>> {
294292
let authorized = authorizer
295293
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableWrite].into())
@@ -302,7 +300,7 @@ async fn put(
302300
let conn = &mut db_pool.get().await?;
303301

304302
let train_schedule_id = train_schedule_id.id;
305-
let ts_changeset: TrainScheduleChangeset = data.into();
303+
let ts_changeset: TrainScheduleChangeset = train_schedule_form.into();
306304

307305
let ts_result = ts_changeset
308306
.update_or_fail(conn, train_schedule_id, || TrainScheduleError::NotFound {
@@ -672,7 +670,11 @@ enum SimulationSummaryResult {
672670
async fn simulation_summary(
673671
app_state: State<AppState>,
674672
Extension(authorizer): AuthorizerExt,
675-
Json(data): Json<SimulationBatchForm>,
673+
Json(SimulationBatchForm {
674+
infra_id,
675+
electrical_profile_set_id,
676+
ids: train_schedule_ids,
677+
}): Json<SimulationBatchForm>,
676678
) -> Result<Json<HashMap<i64, SimulationSummaryResult>>> {
677679
let authorized = authorizer
678680
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into())
@@ -686,12 +688,6 @@ async fn simulation_summary(
686688
let redis_client = app_state.redis.clone();
687689
let core = app_state.core_client.clone();
688690

689-
let SimulationBatchForm {
690-
infra_id,
691-
electrical_profile_set_id,
692-
ids: train_schedule_ids,
693-
} = data;
694-
695691
let infra = Infra::retrieve_or_fail(db_pool.get().await?.deref_mut(), infra_id, || {
696692
TrainScheduleError::InfraNotFound { infra_id }
697693
})

editoast/src/views/v2/train_schedule/projection.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ struct CachedProjectPathTrainResult {
128128
async fn project_path(
129129
app_state: State<AppState>,
130130
Extension(authorizer): AuthorizerExt,
131-
Json(data): Json<ProjectPathForm>,
131+
Json(ProjectPathForm {
132+
infra_id,
133+
ids: train_ids,
134+
path,
135+
electrical_profile_set_id,
136+
}): Json<ProjectPathForm>,
132137
) -> Result<Json<HashMap<i64, ProjectPathTrainResult>>> {
133138
let authorized = authorizer
134139
.check_roles(
@@ -149,12 +154,6 @@ async fn project_path(
149154
let redis_client = app_state.redis.clone();
150155
let core_client = app_state.core_client.clone();
151156

152-
let ProjectPathForm {
153-
infra_id,
154-
ids: train_ids,
155-
path,
156-
electrical_profile_set_id,
157-
} = data;
158157
let ProjectPathInput {
159158
track_section_ranges: path_track_ranges,
160159
routes: path_routes,

editoast/src/views/work_schedules.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ struct WorkScheduleCreateResponse {
140140
async fn create(
141141
State(app_state): State<AppState>,
142142
Extension(authorizer): AuthorizerExt,
143-
Json(data): Json<WorkScheduleCreateForm>,
143+
Json(WorkScheduleCreateForm {
144+
work_schedule_group_name,
145+
work_schedules,
146+
}): Json<WorkScheduleCreateForm>,
144147
) -> Result<Json<WorkScheduleCreateResponse>> {
145148
let authorized = authorizer
146149
.check_roles([BuiltinRole::WorkScheduleWrite].into())
@@ -153,20 +156,17 @@ async fn create(
153156
let db_pool = app_state.db_pool_v2.clone();
154157
let conn = &mut db_pool.get().await?;
155158

156-
let work_schedule_create_form = data;
157-
158159
// Create the work_schedule_group
159160
let work_schedule_group = WorkScheduleGroup::changeset()
160-
.name(work_schedule_create_form.work_schedule_group_name.clone())
161+
.name(work_schedule_group_name.clone())
161162
.creation_date(Utc::now().naive_utc())
162163
.create(conn)
163164
.await;
164-
let work_schedule_group = work_schedule_group
165-
.map_err(|e| map_diesel_error(e, work_schedule_create_form.work_schedule_group_name))?;
165+
let work_schedule_group =
166+
work_schedule_group.map_err(|e| map_diesel_error(e, work_schedule_group_name))?;
166167

167168
// Create work schedules
168-
let work_schedules_changesets = work_schedule_create_form
169-
.work_schedules
169+
let work_schedules_changesets = work_schedules
170170
.into_iter()
171171
.map(|work_schedule| work_schedule.into_work_schedule_changeset(work_schedule_group.id))
172172
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)