Skip to content

Commit

Permalink
editoast: refactor views::infra::routes::get_routes_track_ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
hamz2a committed Jun 28, 2024
1 parent c45d995 commit 1ba6ba3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions editoast/src/views/infra/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ mod tests {
let db_pool = app.db_pool();
let empty_infra = create_empty_infra(db_pool.get_ok().deref_mut()).await;

let req = TestRequest::post()
let request = TestRequest::post()
.uri(format!("/infra/{}/objects/TrackSection", empty_infra.id).as_str())
.set_json(["invalid_id"])
.to_request();
let response = call_service(&app.service, req).await;
assert_eq!(response.status(), StatusCode::BAD_REQUEST);

app.fetch(request).assert_status(StatusCode::BAD_REQUEST);
}

#[rstest]
Expand Down
12 changes: 7 additions & 5 deletions editoast/src/views/infra/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,16 @@ async fn get_routes_track_ranges<'a>(
infra: Path<i64>,
params: Query<RouteTrackRangesParams>,
infra_caches: Data<CHashMap<i64, InfraCache>>,
db_pool: Data<DbConnectionPool>,
db_pool: Data<DbConnectionPoolV2>,
) -> Result<Json<Vec<RouteTrackRangesResult>>> {
let infra_id = infra.into_inner();
let conn = &mut db_pool.get().await?;
let infra =
Infra::retrieve_or_fail(conn, infra_id, || InfraApiError::NotFound { infra_id }).await?;
let infra = Infra::retrieve_or_fail(db_pool.get().await?.deref_mut(), infra_id, || {
InfraApiError::NotFound { infra_id }
})
.await?;

let infra_cache = InfraCache::get_or_load(conn, &infra_caches, &infra).await?;
let infra_cache =
InfraCache::get_or_load(db_pool.get().await?.deref_mut(), &infra_caches, &infra).await?;
let graph = Graph::load(&infra_cache);
let routes_cache = infra_cache.routes();
let result = params
Expand Down

0 comments on commit 1ba6ba3

Please sign in to comment.