From 65829a332dbd43abb77f672dab5ddc0f42a84920 Mon Sep 17 00:00:00 2001 From: Loup Federico <16464925+Sh099078@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:50:17 +0100 Subject: [PATCH] fixup! editoast: split temporary_speed_limit_group into two endpoints --- editoast/src/views/infra/delimited_area.rs | 34 ++++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/editoast/src/views/infra/delimited_area.rs b/editoast/src/views/infra/delimited_area.rs index 2be3eeac9b1..00b3af531bb 100644 --- a/editoast/src/views/infra/delimited_area.rs +++ b/editoast/src/views/infra/delimited_area.rs @@ -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; @@ -45,8 +46,13 @@ struct DelimitedAreaForm { } #[derive(Deserialize, Serialize, ToSchema)] -struct DelimitedAreaResponse { - track_ranges: Vec, +enum DelimitedAreaResponse { + Success { + track_ranges: Vec, + }, + InvalidInput { + invalid_locations: Vec<(DirectedLocation, DelimitedAreaError)>, + } } #[derive(Debug, Deserialize, Serialize, ToSchema)] @@ -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")] @@ -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), })) } @@ -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]