Skip to content

Commit

Permalink
editoast: add utoipa annotation for infra/{id}/voltages
Browse files Browse the repository at this point in the history
  • Loading branch information
hamz2a committed May 2, 2024
1 parent 113dbd9 commit cb61aa0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 83 deletions.
67 changes: 36 additions & 31 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions editoast/openapi_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 12 additions & 4 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ crate::routes! {
lock,
unlock,
get_speed_limit_tags,
get_voltages,
},
},
}
Expand Down Expand Up @@ -425,22 +426,29 @@ async fn get_speed_limit_tags(
))
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, IntoParams)]
struct GetVoltagesQueryParams {
#[serde(default)]
include_rolling_stock_modes: bool,
}

/// 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<String>, example = json!(["750V", "1500V", "2500.5V"])),
(status = 404, description = "The infra was not found",),
)
)]
#[get("/voltages")]
async fn get_voltages(
infra: Path<i64>,
infra: Path<InfraIdParam>,
param: Query<GetVoltagesQueryParams>,
db_pool: Data<DbConnectionPool>,
) -> Result<Json<Vec<String>>> {
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 {
Expand All @@ -449,7 +457,7 @@ async fn get_voltages(
include_str!("sql/get_voltages_with_rolling_stocks_modes.sql")
};
let voltages: Vec<Voltage> = sql_query(query)
.bind::<BigInt, _>(infra)
.bind::<BigInt, _>(infra.infra_id)
.load(&mut conn)
.await?;
Ok(Json(voltages.into_iter().map(|el| (el.voltage)).collect()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);
Expand Down
33 changes: 16 additions & 17 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit cb61aa0

Please sign in to comment.