From 98fbefc681e1d0f228c636d09766934564ad08bf Mon Sep 17 00:00:00 2001 From: Leo Valais Date: Tue, 3 Dec 2024 17:31:28 +0100 Subject: [PATCH] editoast: fix minor destructuration inconsistencies Signed-off-by: Leo Valais --- editoast/openapi.yaml | 4 +-- editoast/src/views/infra/mod.rs | 5 ++-- editoast/src/views/timetable.rs | 9 +++---- editoast/src/views/train_schedule.rs | 26 ++++++++----------- .../src/views/train_schedule/projection.rs | 4 +-- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/editoast/openapi.yaml b/editoast/openapi.yaml index 53f213dafad..29362fc945f 100644 --- a/editoast/openapi.yaml +++ b/editoast/openapi.yaml @@ -10072,7 +10072,7 @@ components: enum: - pathfinding_not_found - type: object - description: An error has occured during pathfinding + description: An error has occurred during pathfinding required: - core_error - status @@ -10084,7 +10084,7 @@ components: enum: - pathfinding_failure - type: object - description: An error has occured during computing + description: An error has occurred during computing required: - error_type - status diff --git a/editoast/src/views/infra/mod.rs b/editoast/src/views/infra/mod.rs index 992025a108a..dc64f075337 100644 --- a/editoast/src/views/infra/mod.rs +++ b/editoast/src/views/infra/mod.rs @@ -207,7 +207,7 @@ async fn list( .. }): State, Extension(auth): AuthenticationExt, - pagination_params: Query, + Query(pagination_params): Query, ) -> Result> { let authorized = auth .check_roles([BuiltinRole::InfraRead].into()) @@ -430,7 +430,7 @@ async fn delete( .. }): State, Extension(auth): AuthenticationExt, - infra: Path, + Path(InfraIdParam { infra_id }): Path, ) -> Result { let authorized = auth .check_roles([BuiltinRole::InfraWrite].into()) @@ -440,7 +440,6 @@ async fn delete( return Err(AuthorizationError::Unauthorized.into()); } - let infra_id = infra.infra_id; if Infra::fast_delete_static(db_pool.get().await?, infra_id).await? { infra_caches.remove(&infra_id); Ok(StatusCode::NO_CONTENT) diff --git a/editoast/src/views/timetable.rs b/editoast/src/views/timetable.rs index a78b13f0846..7a1a7fe9b6a 100644 --- a/editoast/src/views/timetable.rs +++ b/editoast/src/views/timetable.rs @@ -185,7 +185,7 @@ async fn post( async fn delete( State(db_pool): State, Extension(auth): AuthenticationExt, - timetable_id: Path, + Path(TimetableIdParam { id }): Path, ) -> Result { let authorized = auth .check_roles([BuiltinRole::TimetableWrite].into()) @@ -195,12 +195,9 @@ async fn delete( return Err(AuthorizationError::Unauthorized.into()); } - let timetable_id = timetable_id.id; let conn = &mut db_pool.get().await?; - Timetable::delete_static_or_fail(conn, timetable_id, || TimetableError::NotFound { - timetable_id, - }) - .await?; + Timetable::delete_static_or_fail(conn, id, || TimetableError::NotFound { timetable_id: id }) + .await?; Ok(StatusCode::NO_CONTENT) } diff --git a/editoast/src/views/train_schedule.rs b/editoast/src/views/train_schedule.rs index 80fd72681bb..609e3d1e3a5 100644 --- a/editoast/src/views/train_schedule.rs +++ b/editoast/src/views/train_schedule.rs @@ -169,7 +169,7 @@ impl From for TrainScheduleChangeset { async fn get( State(db_pool): State, Extension(auth): AuthenticationExt, - train_schedule_id: Path, + Path(TrainScheduleIdParam { id }): Path, ) -> Result> { let authorized = auth .check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into()) @@ -179,13 +179,12 @@ async fn get( return Err(AuthorizationError::Unauthorized.into()); } - let train_schedule_id = train_schedule_id.id; let conn = &mut db_pool.get().await?; - - let train_schedule = TrainSchedule::retrieve_or_fail(conn, train_schedule_id, || { - TrainScheduleError::NotFound { train_schedule_id } - }) - .await?; + let train_schedule = + TrainSchedule::retrieve_or_fail(conn, id, || TrainScheduleError::NotFound { + train_schedule_id: id, + }) + .await?; Ok(Json(train_schedule.into())) } @@ -272,7 +271,7 @@ async fn delete( async fn put( State(db_pool): State, Extension(auth): AuthenticationExt, - train_schedule_id: Path, + Path(TrainScheduleIdParam { id }): Path, Json(train_schedule_form): Json, ) -> Result> { let authorized = auth @@ -284,13 +283,10 @@ async fn put( } let conn = &mut db_pool.get().await?; - - let train_schedule_id = train_schedule_id.id; let ts_changeset: TrainScheduleChangeset = train_schedule_form.into(); - let ts_result = ts_changeset - .update_or_fail(conn, train_schedule_id, || TrainScheduleError::NotFound { - train_schedule_id, + .update_or_fail(conn, id, || TrainScheduleError::NotFound { + train_schedule_id: id, }) .await?; @@ -635,9 +631,9 @@ enum SimulationSummaryResult { }, /// Pathfinding not found PathfindingNotFound(PathfindingNotFound), - /// An error has occured during pathfinding + /// An error has occurred during pathfinding PathfindingFailure { core_error: InternalError }, - /// An error has occured during computing + /// An error has occurred during computing SimulationFailed { error_type: String }, /// InputError PathfindingInputError(PathfindingInputError), diff --git a/editoast/src/views/train_schedule/projection.rs b/editoast/src/views/train_schedule/projection.rs index 6c06a73c29a..8bfa58abdae 100644 --- a/editoast/src/views/train_schedule/projection.rs +++ b/editoast/src/views/train_schedule/projection.rs @@ -288,11 +288,11 @@ async fn project_path( let cached_value = CachedProjectPathTrainResult { space_time_curves: space_time_curves .get(id) - .expect("Space time curves not availabe for train") + .expect("Space time curves not available for train") .clone(), signal_updates: signal_updates .get(id) - .expect("Signal update not availabe for train") + .expect("Signal update not available for train") .clone(), }; hit_cache.insert(*id, cached_value.clone());