Skip to content

Commit

Permalink
fixup! editoast: split temporary_speed_limit_group into two endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh099078 committed Nov 18, 2024
1 parent 1557ed0 commit 65829a3
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions editoast/src/views/infra/delimited_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{
collections::{HashMap, HashSet},
result::Result as StdResult,
};
use axum::http::StatusCode;
use thiserror::Error;
use utoipa::ToSchema;
use editoast_derive::EditoastError;
Expand All @@ -45,8 +46,13 @@ struct DelimitedAreaForm {
}

#[derive(Deserialize, Serialize, ToSchema)]
struct DelimitedAreaResponse {
track_ranges: Vec<DirectionalTrackRange>,
enum DelimitedAreaResponse {
Success {
track_ranges: Vec<DirectionalTrackRange>,
},
InvalidInput {
invalid_locations: Vec<(DirectedLocation, DelimitedAreaError)>,
}
}

#[derive(Debug, Deserialize, Serialize, ToSchema)]
Expand All @@ -56,7 +62,7 @@ struct DirectedLocation {
direction: Direction,
}

#[derive(Debug, Error, EditoastError)]
#[derive(Debug, Error,Serialize, Deserialize, EditoastError)]
#[editoast_error(base_id = "delimited_area")]
enum DelimitedAreaError {
#[error("Track '{0}' does not exist")]
Expand Down Expand Up @@ -133,12 +139,19 @@ async fn delimited_area(

if !(invalid_exits.is_empty() && invalid_entries.is_empty()) {
// Throw an error 4xx which contains the list of invalid input locations
todo!()
let location_errors = HashMap::new();
return Err(InternalError {
// TODO
status: StatusCode::BAD_REQUEST,
error_type: "".to_string(),
context: location_errors,
message: "Some locations were invalid".to_string()
});
}

// Retrieve the track ranges

Ok(Json(DelimitedAreaResponse {
Ok(Json(DelimitedAreaResponse::Success {
track_ranges: track_ranges_from_locations(valid_entries, valid_exits, &graph, &infra_cache),
}))
}
Expand Down Expand Up @@ -484,10 +497,13 @@ mod tests {
"exits": exits,
}
));
let DelimitedAreaResponse { track_ranges } =
app.fetch(request).assert_status(StatusCode::OK).json_into();

track_ranges
if let DelimitedAreaResponse::Success { track_ranges } =
app.fetch(request).assert_status(StatusCode::OK).json_into()
{
track_ranges
} else {
panic!("Request to delimited_area endpoint failed")
}
}

#[rstest]
Expand Down

0 comments on commit 65829a3

Please sign in to comment.