Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast: add utoipa annotation for infra/{id}/switch_types #7370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions editoast/editoast_schemas/src/infra/switch_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ editoast_common::schemas! {
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
#[schema(example = json!(
{
"id": "Point",
"ports": ["LEFT", "RIGHT", "BASE"],
"groups": {
"LEFT": { "src": "BASE", "dst": "LEFT" },
"RIGHT": { "src": "BASE", "dst": "RIGHT" }
}
}
))]
pub struct SwitchType {
#[schema(inline)]
pub id: Identifier,
Expand Down
73 changes: 38 additions & 35 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7780,6 +7780,19 @@ components:
type: object
SwitchType:
additionalProperties: false
example:
groups:
LEFT:
dst: LEFT
src: BASE
RIGHT:
dst: RIGHT
src: BASE
id: Point
ports:
- LEFT
- RIGHT
- BASE
properties:
groups:
additionalProperties:
Expand Down Expand Up @@ -9429,41 +9442,6 @@ paths:
summary: Serialize an infra to railjson
tags:
- infra
/infra/{id}/switch_types/:
get:
parameters:
- description: infra id
in: path
name: id
required: true
schema:
type: integer
responses:
'200':
content:
application/json:
schema:
items:
description: A switch type following Railjson spec
example:
groups:
LEFT:
dst: LEFT
src: BASE
RIGHT:
dst: RIGHT
src: BASE
id: Point
ports:
- LEFT
- RIGHT
- BASE
type: object
type: array
description: A list of switch types
summary: Retrieve a list of switch types
tags:
- infra
/infra/{infra_id}/attached/{track_id}/:
get:
description: Retrieve all objects attached to a given track
Expand Down Expand Up @@ -9788,6 +9766,31 @@ paths:
summary: Returns the set of speed limit tags for a given infra
tags:
- infra
/infra/{infra_id}/switch_types/:
get:
description: Return the railjson list of switch types
parameters:
- description: An existing infra ID
in: path
name: infra_id
required: true
schema:
format: int64
type: integer
responses:
'200':
content:
application/json:
schema:
items:
$ref: '#/components/schemas/SwitchType'
type: array
description: A list of switch types
'404':
description: The infra was not found
summary: Return the railjson list of switch types
tags:
- infra
/infra/{infra_id}/unlock/:
post:
description: Unlock an infra
Expand Down
29 changes: 0 additions & 29 deletions editoast/openapi_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,35 +312,6 @@ paths:
items:
$ref: "#/components/schemas/InfraError"

/infra/{id}/switch_types/:
get:
tags:
- infra
summary: Retrieve a list of switch types
parameters:
- in: path
name: id
schema:
type: integer
description: infra id
required: true
responses:
200:
description: A list of switch types
content:
application/json:
schema:
type: array
items:
type: object
description: A switch type following Railjson spec
example:
id: Point
ports: [LEFT, RIGHT, BASE]
groups:
LEFT: { src: BASE, dst: LEFT }
RIGHT: { src: BASE, dst: RIGHT }

/infra/refresh/:
post:
tags:
Expand Down
15 changes: 12 additions & 3 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ crate::routes! {
unlock,
get_speed_limit_tags,
get_voltages,
get_switch_types,
},
get_all_voltages,
},
Expand Down Expand Up @@ -374,15 +375,23 @@ async fn rename(
}

/// Return the railjson list of switch types
#[utoipa::path(
tag = "infra",
params(InfraIdParam),
responses(
(status = 200, description = "A list of switch types", body = Vec<SwitchType>),
(status = 404, description = "The infra was not found"),
)
)]
#[get("/switch_types")]
async fn get_switch_types(
infra: Path<i64>,
infra: Path<InfraIdParam>,
db_pool: Data<DbConnectionPool>,
infra_caches: Data<CHashMap<i64, InfraCache>>,
) -> Result<Json<Vec<SwitchType>>> {
let conn = &mut db_pool.get().await?;
let infra = Infra::retrieve_or_fail(conn, *infra, || InfraApiError::NotFound {
infra_id: *infra,
let infra = Infra::retrieve_or_fail(conn, infra.infra_id, || InfraApiError::NotFound {
infra_id: infra.infra_id,
})
.await?;

Expand Down
4 changes: 2 additions & 2 deletions front/src/applications/editor/tools/switchEdition/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const trackNodeTypeOrder = [
];

export const useSwitchTypes = (infraID: number | undefined) => {
const { data } = osrdEditoastApi.endpoints.getInfraByIdSwitchTypes.useQuery(
{ id: infraID as number },
const { data } = osrdEditoastApi.endpoints.getInfraByInfraIdSwitchTypes.useQuery(
{ infraId: infraID as number },
{ skip: !infraID }
);
let orderedData = [] as SwitchType[];
Expand Down
36 changes: 24 additions & 12 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,6 @@ const injectedRtkApi = api
query: (queryArg) => ({ url: `/infra/${queryArg.id}/railjson/` }),
providesTags: ['infra'],
}),
getInfraByIdSwitchTypes: build.query<
GetInfraByIdSwitchTypesApiResponse,
GetInfraByIdSwitchTypesApiArg
>({
query: (queryArg) => ({ url: `/infra/${queryArg.id}/switch_types/` }),
providesTags: ['infra'],
}),
getInfraByInfraIdAttachedAndTrackId: build.query<
GetInfraByInfraIdAttachedAndTrackIdApiResponse,
GetInfraByInfraIdAttachedAndTrackIdApiArg
Expand Down Expand Up @@ -287,6 +280,13 @@ const injectedRtkApi = api
query: (queryArg) => ({ url: `/infra/${queryArg.infraId}/speed_limit_tags/` }),
providesTags: ['infra'],
}),
getInfraByInfraIdSwitchTypes: build.query<
GetInfraByInfraIdSwitchTypesApiResponse,
GetInfraByInfraIdSwitchTypesApiArg
>({
query: (queryArg) => ({ url: `/infra/${queryArg.infraId}/switch_types/` }),
providesTags: ['infra'],
}),
postInfraByInfraIdUnlock: build.mutation<
PostInfraByInfraIdUnlockApiResponse,
PostInfraByInfraIdUnlockApiArg
Expand Down Expand Up @@ -1142,11 +1142,6 @@ export type GetInfraByIdRailjsonApiArg = {
/** Infra ID */
id: number;
};
export type GetInfraByIdSwitchTypesApiResponse = /** status 200 A list of switch types */ object[];
export type GetInfraByIdSwitchTypesApiArg = {
/** infra id */
id: number;
};
export type GetInfraByInfraIdAttachedAndTrackIdApiResponse =
/** status 200 All objects attached to the given track (arranged by types) */ {
[key: string]: string[];
Expand Down Expand Up @@ -1239,6 +1234,12 @@ export type GetInfraByInfraIdSpeedLimitTagsApiArg = {
/** An existing infra ID */
infraId: number;
};
export type GetInfraByInfraIdSwitchTypesApiResponse =
/** status 200 A list of switch types */ SwitchType[];
export type GetInfraByInfraIdSwitchTypesApiArg = {
/** An existing infra ID */
infraId: number;
};
export type PostInfraByInfraIdUnlockApiResponse = unknown;
export type PostInfraByInfraIdUnlockApiArg = {
/** An existing infra ID */
Expand Down Expand Up @@ -1984,6 +1985,17 @@ export type PathfindingInput = {
ending: PathfindingTrackLocationInput;
starting: PathfindingTrackLocationInput;
};
export type SwitchPortConnection = {
dst: string;
src: string;
};
export type SwitchType = {
groups: {
[key: string]: SwitchPortConnection[];
};
id: string;
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
ports: string[];
};
export type LightModeEffortCurves = {
is_electric: boolean;
};
Expand Down
Loading