Skip to content

Commit

Permalink
editoast: add utoipa annotation for infra/{id}/speed_limit_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
hamz2a committed Apr 30, 2024
1 parent e21379d commit 93c192e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 70 deletions.
52 changes: 28 additions & 24 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9320,30 +9320,6 @@ paths:
summary: Serialize an infra to railjson
tags:
- infra
/infra/{id}/speed_limit_tags/:
get:
parameters:
- description: Infra id
in: path
name: id
required: true
schema:
type: integer
responses:
'200':
content:
application/json:
schema:
example:
- freight
- heavy_load
items:
type: string
type: array
description: Tags list
summary: List all speed limit tags
tags:
- infra
/infra/{id}/switch_types/:
get:
parameters:
Expand Down Expand Up @@ -9706,6 +9682,34 @@ paths:
tags:
- infra
- routes
/infra/{infra_id}/speed_limit_tags/:
get:
description: Returns the set of speed limit tags for a given infra
parameters:
- description: An existing infra ID
in: path
name: infra_id
required: true
schema:
format: int64
type: integer
responses:
'200':
content:
application/json:
example:
- freight
- heavy_load
schema:
items:
type: string
type: array
description: List all speed limit tags
'404':
description: The infra was not found
summary: Returns the set of speed limit tags for a given infra
tags:
- infra
/infra/{infra_id}/unlock/:
post:
description: Unlock an infra
Expand Down
23 changes: 0 additions & 23 deletions editoast/openapi_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,29 +388,6 @@ paths:
type: string
example: ["750V", "1500V", "2500.5V"]

/infra/{id}/speed_limit_tags/:
get:
tags:
- infra
summary: List all speed limit tags
parameters:
- in: path
name: id
schema:
type: integer
description: Infra id
required: true
responses:
200:
description: Tags list
content:
application/json:
schema:
type: array
items:
type: string
example: ["freight", "heavy_load"]

/infra/{id}/voltages/:
get:
tags:
Expand Down
14 changes: 11 additions & 3 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ crate::routes! {
attached::routes(),
lock,
unlock,
get_speed_limit_tags,
},
},
}
Expand Down Expand Up @@ -395,21 +396,28 @@ async fn get_switch_types(
}

/// Returns the set of speed limit tags for a given infra
#[utoipa::path(
tag = "infra",
params(InfraIdParam),
responses(
(status = 200, description = "List all speed limit tags", body = Vec<String>, example = json!(["freight", "heavy_load"])),
(status = 404, description = "The infra was not found"),
)
)]
#[get("/speed_limit_tags")]
async fn get_speed_limit_tags(
infra: Path<i64>,
infra: Path<InfraIdParam>,
db_pool: Data<DbConnectionPool>,
) -> Result<Json<Vec<String>>> {
use diesel_async::RunQueryDsl;
let infra = infra.into_inner();
let mut conn = db_pool.get().await?;
let speed_limits_tags: Vec<SpeedLimitTags> = sql_query(
"SELECT DISTINCT jsonb_object_keys(data->'speed_limit_by_tag') AS tag
FROM infra_object_speed_section
WHERE infra_id = $1
ORDER BY tag",
)
.bind::<BigInt, _>(infra)
.bind::<BigInt, _>(infra.infra_id)
.load(&mut conn)
.await?;
Ok(Json(
Expand Down
9 changes: 5 additions & 4 deletions front/src/applications/editor/components/LayersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ const LayersModal: FC<LayersModalProps> = ({
const [selectedLayers, setSelectedLayers] = useState<Set<Layer>>(initialLayers);
const infraID = useInfraID();

const { data: speedLimitTags } = osrdEditoastApi.endpoints.getInfraByIdSpeedLimitTags.useQuery(
{ id: infraID as number },
{ skip: isNil(infraID) }
);
const { data: speedLimitTags } =
osrdEditoastApi.endpoints.getInfraByInfraIdSpeedLimitTags.useQuery(
{ infraId: infraID as number },
{ skip: isNil(infraID) }
);
const DEFAULT_SPEED_LIMIT_TAG = useMemo(() => t('map-settings:noSpeedLimitByTag'), [t]);
const selectionCounts = useMemo(
() =>
Expand Down
4 changes: 2 additions & 2 deletions front/src/common/Map/Settings/MapSettingsSpeedLimits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const FormatSwitch = ({ name, icon: IconComponent, color = '', disabled }: Forma
data: tagsList,
isError: isGetSpeedLimitTagsError,
error: getSpeedLimitTagsError,
} = osrdEditoastApi.endpoints.getInfraByIdSpeedLimitTags.useQuery(
{ id: infraID as number },
} = osrdEditoastApi.endpoints.getInfraByInfraIdSpeedLimitTags.useQuery(
{ infraId: infraID as number },
{
skip: !infraID,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const useStoreDataForSpeedLimitByTagSelector = () => {
};

const { data: speedLimitsByTags = [], error } =
osrdEditoastApi.endpoints.getInfraByIdSpeedLimitTags.useQuery(
osrdEditoastApi.endpoints.getInfraByInfraIdSpeedLimitTags.useQuery(
{
id: infraID as number,
infraId: infraID as number,
},
{ skip: !infraID }
);
Expand Down
25 changes: 13 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'],
}),
getInfraByIdSpeedLimitTags: build.query<
GetInfraByIdSpeedLimitTagsApiResponse,
GetInfraByIdSpeedLimitTagsApiArg
>({
query: (queryArg) => ({ url: `/infra/${queryArg.id}/speed_limit_tags/` }),
providesTags: ['infra'],
}),
getInfraByIdSwitchTypes: build.query<
GetInfraByIdSwitchTypesApiResponse,
GetInfraByIdSwitchTypesApiArg
Expand Down Expand Up @@ -297,6 +290,13 @@ const injectedRtkApi = api
}),
providesTags: ['infra', 'routes'],
}),
getInfraByInfraIdSpeedLimitTags: build.query<
GetInfraByInfraIdSpeedLimitTagsApiResponse,
GetInfraByInfraIdSpeedLimitTagsApiArg
>({
query: (queryArg) => ({ url: `/infra/${queryArg.infraId}/speed_limit_tags/` }),
providesTags: ['infra'],
}),
postInfraByInfraIdUnlock: build.mutation<
PostInfraByInfraIdUnlockApiResponse,
PostInfraByInfraIdUnlockApiArg
Expand Down Expand Up @@ -1134,11 +1134,6 @@ export type GetInfraByIdRailjsonApiArg = {
/** Infra ID */
id: number;
};
export type GetInfraByIdSpeedLimitTagsApiResponse = /** status 200 Tags list */ string[];
export type GetInfraByIdSpeedLimitTagsApiArg = {
/** Infra id */
id: number;
};
export type GetInfraByIdSwitchTypesApiResponse = /** status 200 A list of switch types */ object[];
export type GetInfraByIdSwitchTypesApiArg = {
/** infra id */
Expand Down Expand Up @@ -1237,6 +1232,12 @@ export type GetInfraByInfraIdRoutesAndWaypointTypeWaypointIdApiArg = {
/** Waypoint ID */
waypointId: string;
};
export type GetInfraByInfraIdSpeedLimitTagsApiResponse =
/** status 200 List all speed limit tags */ string[];
export type GetInfraByInfraIdSpeedLimitTagsApiArg = {
/** An existing infra ID */
infraId: number;
};
export type PostInfraByInfraIdUnlockApiResponse = unknown;
export type PostInfraByInfraIdUnlockApiArg = {
/** An existing infra ID */
Expand Down

0 comments on commit 93c192e

Please sign in to comment.