diff --git a/editoast/openapi.yaml b/editoast/openapi.yaml index d16016a0bfb..f87347ef625 100644 --- a/editoast/openapi.yaml +++ b/editoast/openapi.yaml @@ -9355,37 +9355,6 @@ paths: summary: Retrieve a list of switch types tags: - infra - /infra/{id}/voltages/: - get: - parameters: - - description: Infra ID - in: path - name: id - required: true - schema: - type: integer - - description: include rolling stocks modes or not - in: query - name: include_rolling_stock_modes - required: false - schema: - type: boolean - responses: - '200': - content: - application/json: - schema: - example: - - 750V - - 1500V - - 2500.5V - items: - type: string - type: array - description: Voltages list - summary: List all voltages - tags: - - infra /infra/{infra_id}/attached/{track_id}/: get: description: Retrieve all objects attached to a given track @@ -9729,6 +9698,42 @@ paths: summary: Unlock an infra tags: - infra + /infra/{infra_id}/voltages/: + get: + description: |- + Returns the set of voltages for a given infra and/or rolling_stocks modes. + If include_rolling_stocks_modes is true, it returns also rolling_stocks modes. + parameters: + - description: An existing infra ID + in: path + name: infra_id + required: true + schema: + format: int64 + type: integer + - in: query + name: include_rolling_stock_modes + required: false + schema: + type: boolean + responses: + '200': + content: + application/json: + example: + - 750V + - 1500V + - 2500.5V + schema: + items: + type: string + type: array + description: Voltages list + '404': + description: The infra was not found + summary: Returns the set of voltages for a given infra and/or rolling_stocks modes. + tags: + - infra /layers/layer/{layer_slug}/mvt/{view_slug}/: get: description: Returns layer view metadata to query tiles diff --git a/editoast/openapi_legacy.yaml b/editoast/openapi_legacy.yaml index d18090bac31..f1c36620982 100644 --- a/editoast/openapi_legacy.yaml +++ b/editoast/openapi_legacy.yaml @@ -388,35 +388,6 @@ paths: type: string example: ["750V", "1500V", "2500.5V"] - /infra/{id}/voltages/: - get: - tags: - - infra - summary: List all voltages - parameters: - - in: path - name: id - schema: - type: integer - description: Infra ID - required: true - - in: query - name: include_rolling_stock_modes - schema: - type: boolean - description: include rolling stocks modes or not - required: false - responses: - 200: - description: Voltages list - content: - application/json: - schema: - type: array - items: - type: string - example: ["750V", "1500V", "2500.5V"] - /infra/{id}/objects/{object_type}/: post: tags: diff --git a/editoast/src/views/infra/mod.rs b/editoast/src/views/infra/mod.rs index a7687e10bbd..1f30731284c 100644 --- a/editoast/src/views/infra/mod.rs +++ b/editoast/src/views/infra/mod.rs @@ -68,6 +68,7 @@ crate::routes! { lock, unlock, get_speed_limit_tags, + get_voltages, }, }, } @@ -425,7 +426,7 @@ async fn get_speed_limit_tags( )) } -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Deserialize, IntoParams)] struct GetVoltagesQueryParams { #[serde(default)] include_rolling_stock_modes: bool, @@ -433,14 +434,21 @@ struct GetVoltagesQueryParams { /// Returns the set of voltages for a given infra and/or rolling_stocks modes. /// If include_rolling_stocks_modes is true, it returns also rolling_stocks modes. +#[utoipa::path( + tag = "infra", + params(InfraIdParam, GetVoltagesQueryParams), + responses( + (status = 200, description = "Voltages list", body = Vec, example = json!(["750V", "1500V", "2500.5V"])), + (status = 404, description = "The infra was not found",), + ) +)] #[get("/voltages")] async fn get_voltages( - infra: Path, + infra: Path, param: Query, db_pool: Data, ) -> Result>> { use diesel_async::RunQueryDsl; - let infra = infra.into_inner(); let include_rolling_stock_modes = param.into_inner().include_rolling_stock_modes; let mut conn = db_pool.get().await?; let query = if !include_rolling_stock_modes { @@ -449,7 +457,7 @@ async fn get_voltages( include_str!("sql/get_voltages_with_rolling_stocks_modes.sql") }; let voltages: Vec = sql_query(query) - .bind::(infra) + .bind::(infra.infra_id) .load(&mut conn) .await?; Ok(Json(voltages.into_iter().map(|el| (el.voltage)).collect())) diff --git a/front/src/applications/editor/tools/rangeEdition/components/RangeEditionLeftPanel.tsx b/front/src/applications/editor/tools/rangeEdition/components/RangeEditionLeftPanel.tsx index 95ecec7872d..3649fa651c4 100644 --- a/front/src/applications/editor/tools/rangeEdition/components/RangeEditionLeftPanel.tsx +++ b/front/src/applications/editor/tools/rangeEdition/components/RangeEditionLeftPanel.tsx @@ -61,9 +61,9 @@ const RangeEditionLeftPanel = () => { const isPSL = speedSectionIsPsl(entity as SpeedSectionEntity); const infraID = useInfraID(); - const { data: voltages } = osrdEditoastApi.endpoints.getInfraByIdVoltages.useQuery( + const { data: voltages } = osrdEditoastApi.endpoints.getInfraByInfraIdVoltages.useQuery( { - id: infraID as number, + infraId: infraID as number, }, { skip: !infraID } ); diff --git a/front/src/common/api/osrdEditoastApi.ts b/front/src/common/api/osrdEditoastApi.ts index 2acba1ded30..878ad55c8c7 100644 --- a/front/src/common/api/osrdEditoastApi.ts +++ b/front/src/common/api/osrdEditoastApi.ts @@ -208,16 +208,6 @@ const injectedRtkApi = api query: (queryArg) => ({ url: `/infra/${queryArg.id}/switch_types/` }), providesTags: ['infra'], }), - getInfraByIdVoltages: build.query< - GetInfraByIdVoltagesApiResponse, - GetInfraByIdVoltagesApiArg - >({ - query: (queryArg) => ({ - url: `/infra/${queryArg.id}/voltages/`, - params: { include_rolling_stock_modes: queryArg.includeRollingStockModes }, - }), - providesTags: ['infra'], - }), getInfraByInfraIdAttachedAndTrackId: build.query< GetInfraByInfraIdAttachedAndTrackIdApiResponse, GetInfraByInfraIdAttachedAndTrackIdApiArg @@ -304,6 +294,16 @@ const injectedRtkApi = api query: (queryArg) => ({ url: `/infra/${queryArg.infraId}/unlock/`, method: 'POST' }), invalidatesTags: ['infra'], }), + getInfraByInfraIdVoltages: build.query< + GetInfraByInfraIdVoltagesApiResponse, + GetInfraByInfraIdVoltagesApiArg + >({ + query: (queryArg) => ({ + url: `/infra/${queryArg.infraId}/voltages/`, + params: { include_rolling_stock_modes: queryArg.includeRollingStockModes }, + }), + providesTags: ['infra'], + }), getLayersLayerByLayerSlugMvtAndViewSlug: build.query< GetLayersLayerByLayerSlugMvtAndViewSlugApiResponse, GetLayersLayerByLayerSlugMvtAndViewSlugApiArg @@ -1139,13 +1139,6 @@ export type GetInfraByIdSwitchTypesApiArg = { /** infra id */ id: number; }; -export type GetInfraByIdVoltagesApiResponse = /** status 200 Voltages list */ string[]; -export type GetInfraByIdVoltagesApiArg = { - /** Infra ID */ - id: number; - /** include rolling stocks modes or not */ - includeRollingStockModes?: boolean; -}; export type GetInfraByInfraIdAttachedAndTrackIdApiResponse = /** status 200 All objects attached to the given track (arranged by types) */ { [key: string]: string[]; @@ -1243,6 +1236,12 @@ export type PostInfraByInfraIdUnlockApiArg = { /** An existing infra ID */ infraId: number; }; +export type GetInfraByInfraIdVoltagesApiResponse = /** status 200 Voltages list */ string[]; +export type GetInfraByInfraIdVoltagesApiArg = { + /** An existing infra ID */ + infraId: number; + includeRollingStockModes?: boolean; +}; export type GetLayersLayerByLayerSlugMvtAndViewSlugApiResponse = /** status 200 Successful Response */ { attribution: string;