Skip to content

Commit

Permalink
editoast, front: add OpenApi annotations for POST /infra/{id}/load
Browse files Browse the repository at this point in the history
  • Loading branch information
leovalais committed May 23, 2024
1 parent 2a61658 commit 573af8c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 70 deletions.
33 changes: 18 additions & 15 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9536,21 +9536,6 @@ paths:
summary: Retrieve a paginated list of errors
tags:
- infra
/infra/{id}/load/:
post:
parameters:
- description: infra id
in: path
name: id
required: true
schema:
type: integer
responses:
'200':
description: No content
summary: Load an infra if not loaded
tags:
- infra
/infra/{id}/objects/{object_type}/:
post:
parameters:
Expand Down Expand Up @@ -9786,6 +9771,24 @@ paths:
summary: Returns the BBoxes of a line
tags:
- infra
/infra/{infra_id}/load/:
post:
parameters:
- description: An existing infra ID
in: path
name: infra_id
required: true
schema:
format: int64
type: integer
responses:
'204':
description: The infra was loaded successfully
'404':
description: The infra was not found
summary: Instructs Core to load an infra
tags:
- infra
/infra/{infra_id}/lock/:
post:
parameters:
Expand Down
16 changes: 0 additions & 16 deletions editoast/openapi_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,6 @@ paths:
items:
$ref: "#/components/schemas/RailjsonObject"

/infra/{id}/load/:
post:
tags:
- infra
summary: Load an infra if not loaded
parameters:
- in: path
name: id
schema:
type: integer
description: infra id
required: true
responses:
200:
description: No content

/infra/{id}/errors/:
get:
tags:
Expand Down
29 changes: 15 additions & 14 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ crate::routes! {
edition::routes(),
),
get,
load,
delete,
put,
clone,
Expand Down Expand Up @@ -568,30 +569,30 @@ pub struct StatePayload {
infra: Option<i64>,
}

/// Builds a Core infra load request, runs it
async fn call_core_infra_load(
infra_id: i64,
/// Instructs Core to load an infra
#[utoipa::path(
tag = "infra",
params(InfraIdParam),
responses(
(status = 204, description = "The infra was loaded successfully"),
(status = 404, description = "The infra was not found"),
)
)]
#[post("/load")]
async fn load(
path: Path<InfraIdParam>,
db_pool: Data<DbConnectionPool>,
core: Data<CoreClient>,
) -> Result<()> {
) -> Result<HttpResponse> {
let conn = &mut db_pool.get().await?;
let infra_id = path.infra_id;
let infra =
Infra::retrieve_or_fail(conn, infra_id, || InfraApiError::NotFound { infra_id }).await?;
let infra_request = InfraLoadRequest {
infra: infra.id,
expected_version: infra.version,
};
infra_request.fetch(core.as_ref()).await?;
Ok(())
}

#[post("/load")]
async fn load(
infra: Path<i64>,
db_pool: Data<DbConnectionPool>,
core: Data<CoreClient>,
) -> Result<HttpResponse> {
call_core_infra_load(*infra, db_pool, core).await?;
Ok(HttpResponse::NoContent().finish())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ const ScenarioV1 = () => {
pollingInterval: !isInfraLoaded ? 1000 : undefined,
}
);
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByIdLoad.useMutation();
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdLoad.useMutation();

useEffect(() => {
if (reloadCount <= 5 && infra && infra.state === 'TRANSIENT_ERROR') {
setTimeout(() => {
reloadInfra({ id: infraId as number }).unwrap();
reloadInfra({ infraId: infraId as number }).unwrap();
setReloadCount((count) => count + 1);
}, 1000);
}
Expand All @@ -140,7 +140,7 @@ const ScenarioV1 = () => {

useEffect(() => {
if (infraId) {
reloadInfra({ id: infraId as number }).unwrap();
reloadInfra({ infraId: infraId as number }).unwrap();
}
}, [infraId]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ const ScenarioV2 = () => {
pollingInterval: !isInfraLoaded ? 1000 : undefined,
}
);
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByIdLoad.useMutation();
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdLoad.useMutation();

useEffect(() => {
if (reloadCount <= 5 && infra && infra.state === 'TRANSIENT_ERROR') {
setTimeout(() => {
reloadInfra({ id: infraId as number }).unwrap();
reloadInfra({ infraId: infraId as number }).unwrap();
setReloadCount((count) => count + 1);
}, 1000);
}
Expand All @@ -135,7 +135,7 @@ const ScenarioV2 = () => {

useEffect(() => {
if (infraId) {
reloadInfra({ id: infraId }).unwrap();
reloadInfra({ infraId }).unwrap();
}
}, [infraId]);

Expand Down
21 changes: 12 additions & 9 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ const injectedRtkApi = api
}),
providesTags: ['infra'],
}),
postInfraByIdLoad: build.mutation<PostInfraByIdLoadApiResponse, PostInfraByIdLoadApiArg>({
query: (queryArg) => ({ url: `/infra/${queryArg.id}/load/`, method: 'POST' }),
invalidatesTags: ['infra'],
}),
postInfraByIdObjectsAndObjectType: build.mutation<
PostInfraByIdObjectsAndObjectTypeApiResponse,
PostInfraByIdObjectsAndObjectTypeApiArg
Expand Down Expand Up @@ -223,6 +219,13 @@ const injectedRtkApi = api
}),
providesTags: ['infra'],
}),
postInfraByInfraIdLoad: build.mutation<
PostInfraByInfraIdLoadApiResponse,
PostInfraByInfraIdLoadApiArg
>({
query: (queryArg) => ({ url: `/infra/${queryArg.infraId}/load/`, method: 'POST' }),
invalidatesTags: ['infra'],
}),
postInfraByInfraIdLock: build.mutation<
PostInfraByInfraIdLockApiResponse,
PostInfraByInfraIdLockApiArg
Expand Down Expand Up @@ -1116,11 +1119,6 @@ export type GetInfraByIdErrorsApiArg = {
/** Whether the response should include errors or warnings */
level?: 'errors' | 'warnings' | 'all';
};
export type PostInfraByIdLoadApiResponse = unknown;
export type PostInfraByIdLoadApiArg = {
/** infra id */
id: number;
};
export type PostInfraByIdObjectsAndObjectTypeApiResponse = /** status 200 No content */ {
/** object's geographic in geojson format */
geographic: Geometry;
Expand Down Expand Up @@ -1185,6 +1183,11 @@ export type GetInfraByInfraIdLinesAndLineCodeBboxApiArg = {
/** A line code */
lineCode: number;
};
export type PostInfraByInfraIdLoadApiResponse = unknown;
export type PostInfraByInfraIdLoadApiArg = {
/** An existing infra ID */
infraId: number;
};
export type PostInfraByInfraIdLockApiResponse = unknown;
export type PostInfraByInfraIdLockApiArg = {
/** An existing infra ID */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ const Pathfinding = ({ zoomToFeature, path }: PathfindingProps) => {
pollingInterval: !isInfraLoaded ? 1000 : undefined,
}
);
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByIdLoad.useMutation();
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdLoad.useMutation();

const {
replaceVias,
Expand All @@ -278,7 +278,7 @@ const Pathfinding = ({ zoomToFeature, path }: PathfindingProps) => {
useEffect(() => {
if (reloadCount <= 5 && infra && infra.state === 'TRANSIENT_ERROR') {
setTimeout(() => {
reloadInfra({ id: infraID as number }).unwrap();
reloadInfra({ infraId: infraID as number }).unwrap();
setReloadCount((count) => count + 1);
}, 1000);
}
Expand All @@ -288,7 +288,7 @@ const Pathfinding = ({ zoomToFeature, path }: PathfindingProps) => {
if (infra) {
switch (infra.state) {
case 'NOT_LOADED': {
reloadInfra({ id: infraID as number }).unwrap();
reloadInfra({ infraId: infraID as number }).unwrap();
setIsInfraLoaded(false);
break;
}
Expand Down Expand Up @@ -445,7 +445,7 @@ const Pathfinding = ({ zoomToFeature, path }: PathfindingProps) => {

useEffect(() => {
if (isInfraError) {
reloadInfra({ id: infraID as number }).unwrap();
reloadInfra({ infraId: infraID as number }).unwrap();
setIsInfraLoaded(false);
}
}, [isInfraError]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>
pollingInterval: !isInfraLoaded ? 1000 : undefined,
}
);
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByIdLoad.useMutation();
const [reloadInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdLoad.useMutation();

const {
updatePathSteps,
Expand All @@ -203,7 +203,7 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>
useEffect(() => {
if (reloadCount <= 5 && infra && infra.state === 'TRANSIENT_ERROR') {
setTimeout(() => {
reloadInfra({ id: infraId as number }).unwrap();
reloadInfra({ infraId: infraId as number }).unwrap();
setReloadCount((count) => count + 1);
}, 1000);
}
Expand All @@ -213,7 +213,7 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>
if (infra) {
switch (infra.state) {
case 'NOT_LOADED': {
reloadInfra({ id: infraId as number }).unwrap();
reloadInfra({ infraId: infraId as number }).unwrap();
setIsInfraLoaded(false);
break;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>

useEffect(() => {
if (isInfraError) {
reloadInfra({ id: infraId as number }).unwrap();
reloadInfra({ infraId: infraId as number }).unwrap();
setIsInfraLoaded(false);
}
}, [isInfraError]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function AddOrEditScenarioModal({
],
}),
});
const [loadInfra] = osrdEditoastApi.endpoints.postInfraByIdLoad.useMutation();
const [loadInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdLoad.useMutation();

const [displayErrors, setDisplayErrors] = useState(false);

Expand Down Expand Up @@ -199,7 +199,7 @@ export default function AddOrEditScenarioModal({
.unwrap()
.then(({ id }) => {
dispatch(updateScenarioID(id));
loadInfra({ id: infraID as number }).unwrap();
loadInfra({ infraId: infraID as number }).unwrap();
navigate(`projects/${projectId}/studies/${studyId}/scenarios/${id}`);
closeModal();
})
Expand Down

0 comments on commit 573af8c

Please sign in to comment.