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 4, 2024
1 parent 5b79743 commit 6968585
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 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
24 changes: 8 additions & 16 deletions editoast/src/views/timetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct TimetableIdParam {
async fn get(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Path(timetable_id): Path<TimetableIdParam>,
Path(TimetableIdParam { id: timetable_id }): Path<TimetableIdParam>,
) -> Result<Json<TimetableDetailedResult>> {
let authorized = auth
.check_roles([BuiltinRole::TimetableRead].into())
Expand All @@ -132,15 +132,11 @@ async fn get(
return Err(AuthorizationError::Unauthorized.into());
}

let timetable_id = timetable_id.id;
// Return the timetable

let conn = &mut db_pool.get().await?;
let timetable = TimetableWithTrains::retrieve_or_fail(conn, timetable_id, || {
TimetableError::NotFound { timetable_id }
})
.await?;

Ok(Json(timetable.into()))
}

Expand Down Expand Up @@ -185,7 +181,7 @@ async fn post(
async fn delete(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
timetable_id: Path<TimetableIdParam>,
Path(TimetableIdParam { id: timetable_id }): Path<TimetableIdParam>,
) -> Result<impl IntoResponse> {
let authorized = auth
.check_roles([BuiltinRole::TimetableWrite].into())
Expand All @@ -195,7 +191,6 @@ 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,
Expand All @@ -217,7 +212,7 @@ async fn delete(
async fn train_schedule(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Path(timetable_id): Path<TimetableIdParam>,
Path(TimetableIdParam { id: timetable_id }): Path<TimetableIdParam>,
Json(train_schedules): Json<Vec<TrainScheduleBase>>,
) -> Result<Json<Vec<TrainScheduleResult>>> {
let authorized = auth
Expand All @@ -230,7 +225,6 @@ async fn train_schedule(

let conn = &mut db_pool.get().await?;

let timetable_id = timetable_id.id;
TimetableWithTrains::retrieve_or_fail(conn, timetable_id, || TimetableError::NotFound {
timetable_id,
})
Expand Down Expand Up @@ -278,9 +272,11 @@ async fn conflicts(
..
}): State<AppState>,
Extension(auth): AuthenticationExt,
Path(timetable_id): Path<TimetableIdParam>,
Query(infra_id_query): Query<InfraIdQueryParam>,
Query(electrical_profile_set_id_query): Query<ElectricalProfileSetIdQueryParam>,
Path(TimetableIdParam { id: timetable_id }): Path<TimetableIdParam>,
Query(InfraIdQueryParam { infra_id }): Query<InfraIdQueryParam>,
Query(ElectricalProfileSetIdQueryParam {
electrical_profile_set_id,
}): Query<ElectricalProfileSetIdQueryParam>,
) -> Result<Json<Vec<Conflict>>> {
let authorized = auth
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into())
Expand All @@ -290,10 +286,6 @@ async fn conflicts(
return Err(AuthorizationError::Unauthorized.into());
}

let timetable_id = timetable_id.id;
let infra_id = infra_id_query.infra_id;
let electrical_profile_set_id = electrical_profile_set_id_query.electrical_profile_set_id;

// 1. Retrieve Timetable / Infra / Trains / Simultion
let timetable_trains =
TimetableWithTrains::retrieve_or_fail(&mut db_pool.get().await?, timetable_id, || {
Expand Down
31 changes: 15 additions & 16 deletions editoast/src/views/train_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ impl From<TrainScheduleForm> for TrainScheduleChangeset {
async fn get(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
train_schedule_id: Path<TrainScheduleIdParam>,
Path(TrainScheduleIdParam {
id: train_schedule_id,
}): Path<TrainScheduleIdParam>,
) -> Result<Json<TrainScheduleResult>> {
let authorized = auth
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into())
Expand All @@ -179,9 +181,7 @@ 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 }
})
Expand Down Expand Up @@ -272,7 +272,9 @@ async fn delete(
async fn put(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
train_schedule_id: Path<TrainScheduleIdParam>,
Path(TrainScheduleIdParam {
id: train_schedule_id,
}): Path<TrainScheduleIdParam>,
Json(train_schedule_form): Json<TrainScheduleForm>,
) -> Result<Json<TrainScheduleResult>> {
let authorized = auth
Expand All @@ -284,10 +286,7 @@ 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,
Expand Down Expand Up @@ -326,9 +325,13 @@ async fn simulation(
..
}): State<AppState>,
Extension(auth): AuthenticationExt,
Path(train_schedule_id): Path<TrainScheduleIdParam>,
Query(infra_id_query): Query<InfraIdQueryParam>,
Query(electrical_profile_set_id_query): Query<ElectricalProfileSetIdQueryParam>,
Path(TrainScheduleIdParam {
id: train_schedule_id,
}): Path<TrainScheduleIdParam>,
Query(InfraIdQueryParam { infra_id }): Query<InfraIdQueryParam>,
Query(ElectricalProfileSetIdQueryParam {
electrical_profile_set_id,
}): Query<ElectricalProfileSetIdQueryParam>,
) -> Result<Json<SimulationResponse>> {
let authorized = auth
.check_roles([BuiltinRole::InfraRead, BuiltinRole::TimetableRead].into())
Expand All @@ -338,10 +341,6 @@ async fn simulation(
return Err(AuthorizationError::Unauthorized.into());
}

let infra_id = infra_id_query.infra_id;
let electrical_profile_set_id = electrical_profile_set_id_query.electrical_profile_set_id;
let train_schedule_id = train_schedule_id.id;

// Retrieve infra or fail
let infra = Infra::retrieve_or_fail(&mut db_pool.get().await?, infra_id, || {
TrainScheduleError::InfraNotFound { infra_id }
Expand Down Expand Up @@ -635,9 +634,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 6968585

Please sign in to comment.