Skip to content

Commit b0dfe9f

Browse files
committed
editoast: remove /rollingstock/{id}/check_usage
That endpoint is no longuer exposed. It was used as a check before removing a rolling stock. The check is now done directly on the delete action.
1 parent 0de0f5b commit b0dfe9f

File tree

1 file changed

+2
-122
lines changed
  • editoast/src/views/rolling_stocks

1 file changed

+2
-122
lines changed

editoast/src/views/rolling_stocks/mod.rs

+2-122
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ pub enum RollingStockError {
6161
pub fn routes() -> impl HttpServiceFactory {
6262
scope("/rolling_stock")
6363
.service((get_power_restrictions, get, create, update, delete))
64-
.service(scope("/{rolling_stock_id}").service((
65-
create_livery,
66-
update_locked,
67-
check_rolling_stock_usage,
68-
)))
64+
.service(scope("/{rolling_stock_id}").service((create_livery, update_locked)))
6965
}
7066

7167
#[get("/{rolling_stock_id}")]
@@ -306,22 +302,6 @@ pub struct TrainScheduleScenarioStudyProject {
306302
pub scenario_name: String,
307303
}
308304

309-
#[derive(Debug, Serialize, Deserialize, PartialEq)]
310-
struct UsageResponse {
311-
usage: Vec<TrainScheduleScenarioStudyProject>,
312-
}
313-
314-
#[get("/check_usage")]
315-
async fn check_rolling_stock_usage(
316-
db_pool: Data<DbPool>,
317-
rolling_stock_id: Path<i64>,
318-
) -> Result<Json<UsageResponse>> {
319-
let rolling_stock_id = rolling_stock_id.into_inner();
320-
get_rolling_stock_usage(db_pool, rolling_stock_id)
321-
.await
322-
.map(|trains| Json(UsageResponse { usage: trains }))
323-
}
324-
325305
async fn get_rolling_stock_usage(
326306
db_pool: Data<DbPool>,
327307
rolling_stock_id: i64,
@@ -482,10 +462,7 @@ pub mod tests {
482462
use std::vec;
483463

484464
use super::RollingStockError;
485-
use super::{
486-
retrieve_existing_rolling_stock, RollingStock, TrainScheduleScenarioStudyProject,
487-
UsageResponse,
488-
};
465+
use super::{retrieve_existing_rolling_stock, RollingStock, TrainScheduleScenarioStudyProject};
489466
use crate::fixtures::tests::{
490467
db_pool, get_fast_rolling_stock, get_other_rolling_stock, named_fast_rolling_stock,
491468
named_other_rolling_stock, train_schedule_with_scenario,
@@ -853,103 +830,6 @@ pub mod tests {
853830
call_service(&app, rolling_stock_delete_request(rolling_stock_id)).await;
854831
}
855832

856-
#[rstest]
857-
async fn check_usage_rolling_stock_not_found() {
858-
let app = create_test_service().await;
859-
let rolling_stock_id = 314159;
860-
let response = call_service(
861-
&app,
862-
TestRequest::get()
863-
.uri(format!("/rolling_stock/{}/check_usage", rolling_stock_id).as_str())
864-
.to_request(),
865-
)
866-
.await;
867-
assert_eq!(response.status(), StatusCode::NOT_FOUND);
868-
assert_editoast_error_type!(response, RollingStockError::NotFound { rolling_stock_id });
869-
}
870-
871-
#[rstest]
872-
async fn check_usage_no_train_schedule_for_this_rolling_stock(db_pool: Data<DbPool>) {
873-
// GIVEN
874-
let rolling_stock = named_fast_rolling_stock(
875-
"fast_rolling_stock_check_usage_no_train_schedule_for_this_rolling_stock",
876-
db_pool,
877-
)
878-
.await;
879-
let app = create_test_service().await;
880-
let rolling_stock_id = rolling_stock.id();
881-
882-
// WHEN
883-
let response = call_service(
884-
&app,
885-
TestRequest::get()
886-
.uri(format!("/rolling_stock/{}/check_usage", rolling_stock_id).as_str())
887-
.to_request(),
888-
)
889-
.await;
890-
891-
// THEN
892-
let response_body: UsageResponse = assert_status_and_read!(response, StatusCode::OK);
893-
let expected_body = UsageResponse { usage: Vec::new() };
894-
assert_eq!(response_body, expected_body);
895-
}
896-
897-
/// Tests`/rolling_stock/{rolling_stock_id}/check_usage` endpoint.
898-
/// Initial conditions: one `TrainSchedule` using the given `rolling_stock_id`.
899-
/// It should return the `TrainSchedule`, `project`/`study`/`scenario` ids/names
900-
#[rstest]
901-
async fn check_usage_one_train_schedule() {
902-
// GIVEN
903-
let app = create_test_service().await;
904-
let train_schedule_with_scenario =
905-
train_schedule_with_scenario("test_single_simulation_bare_minimum_payload").await;
906-
let rolling_stock_id = train_schedule_with_scenario.rolling_stock.id();
907-
908-
// WHEN
909-
let response = call_service(
910-
&app,
911-
TestRequest::get()
912-
.uri(format!("/rolling_stock/{}/check_usage", rolling_stock_id).as_str())
913-
.to_request(),
914-
)
915-
.await;
916-
917-
// THEN
918-
let response_body: UsageResponse = assert_status_and_read!(response, StatusCode::OK);
919-
let expected_body = UsageResponse {
920-
usage: vec![TrainScheduleScenarioStudyProject {
921-
train_schedule_id: train_schedule_with_scenario.train_schedule.id(),
922-
train_name: train_schedule_with_scenario
923-
.train_schedule
924-
.model
925-
.train_name
926-
.clone(),
927-
scenario_id: train_schedule_with_scenario.scenario.id(),
928-
scenario_name: train_schedule_with_scenario
929-
.scenario
930-
.model
931-
.name
932-
.clone()
933-
.unwrap(),
934-
study_id: train_schedule_with_scenario.study.id(),
935-
study_name: train_schedule_with_scenario
936-
.study
937-
.model
938-
.name
939-
.clone()
940-
.unwrap(),
941-
project_id: train_schedule_with_scenario.project.id(),
942-
project_name: train_schedule_with_scenario
943-
.project
944-
.model
945-
.name
946-
.clone()
947-
.unwrap(),
948-
}],
949-
};
950-
assert_eq!(response_body, expected_body);
951-
}
952-
953833
#[rstest]
954834
async fn delete_used_rolling_stock_should_fail() {
955835
// GIVEN

0 commit comments

Comments
 (0)