Skip to content

Commit

Permalink
editoast: fix minor destructuration inconsistencies
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Valais <[email protected]>
  • Loading branch information
leovalais committed Dec 3, 2024
1 parent 544cd0d commit 98fbefc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
4 changes: 2 additions & 2 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async fn list(
..
}): State<AppState>,
Extension(auth): AuthenticationExt,
pagination_params: Query<PaginationQueryParams>,
Query(pagination_params): Query<PaginationQueryParams>,
) -> Result<Json<InfraListResponse>> {
let authorized = auth
.check_roles([BuiltinRole::InfraRead].into())
Expand Down Expand Up @@ -430,7 +430,7 @@ async fn delete(
..
}): State<AppState>,
Extension(auth): AuthenticationExt,
infra: Path<InfraIdParam>,
Path(InfraIdParam { infra_id }): Path<InfraIdParam>,
) -> Result<impl IntoResponse> {
let authorized = auth
.check_roles([BuiltinRole::InfraWrite].into())
Expand All @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions editoast/src/views/timetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async fn post(
async fn delete(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
timetable_id: Path<TimetableIdParam>,
Path(TimetableIdParam { id }): Path<TimetableIdParam>,
) -> Result<impl IntoResponse> {
let authorized = auth
.check_roles([BuiltinRole::TimetableWrite].into())
Expand All @@ -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)
}

Expand Down
26 changes: 11 additions & 15 deletions editoast/src/views/train_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl From<TrainScheduleForm> for TrainScheduleChangeset {
async fn get(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
train_schedule_id: Path<TrainScheduleIdParam>,
Path(TrainScheduleIdParam { id }): Path<TrainScheduleIdParam>,
) -> Result<Json<TrainScheduleResult>> {
let authorized = auth
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into())
Expand All @@ -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()))
}

Expand Down Expand Up @@ -272,7 +271,7 @@ async fn delete(
async fn put(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
train_schedule_id: Path<TrainScheduleIdParam>,
Path(TrainScheduleIdParam { id }): Path<TrainScheduleIdParam>,
Json(train_schedule_form): Json<TrainScheduleForm>,
) -> Result<Json<TrainScheduleResult>> {
let authorized = auth
Expand All @@ -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?;

Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/train_schedule/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 98fbefc

Please sign in to comment.