Skip to content

Commit

Permalink
editoast: add utoipa annotation for infra/{id}/unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
hamz2a committed Apr 30, 2024
1 parent 6281c05 commit be2941a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
34 changes: 19 additions & 15 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8736,21 +8736,6 @@ paths:
summary: Retrieve a list of switch types
tags:
- infra
/infra/{id}/unlock/:
post:
parameters:
- description: infra id
in: path
name: id
required: true
schema:
type: integer
responses:
'204':
description: No content
summary: Unlock an infra from edition
tags:
- infra
/infra/{id}/voltages/:
get:
parameters:
Expand Down Expand Up @@ -9078,6 +9063,25 @@ paths:
tags:
- infra
- routes
/infra/{infra_id}/unlock/:
post:
description: Unlock an infra
parameters:
- description: An existing infra ID
in: path
name: infra_id
required: true
schema:
format: int64
type: integer
responses:
'204':
description: The infra was unlocked successfully
'404':
description: The infra was not found
summary: Unlock an infra
tags:
- infra
/layers/layer/{layer_slug}/mvt/{view_slug}/:
get:
description: Returns layer view metadata to query tiles
Expand Down
16 changes: 0 additions & 16 deletions editoast/openapi_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,22 +388,6 @@ paths:
type: string
example: ["750V", "1500V", "2500.5V"]

/infra/{id}/unlock/:
post:
tags:
- infra
summary: Unlock an infra from edition
parameters:
- in: path
name: id
schema:
type: integer
description: infra id
required: true
responses:
204:
description: No content

/infra/{id}/speed_limit_tags/:
get:
tags:
Expand Down
13 changes: 11 additions & 2 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! {
pathfinding::routes(),
attached::routes(),
lock,
unlock,
},
},
}
Expand Down Expand Up @@ -480,9 +481,17 @@ async fn lock(infra: Path<InfraIdParam>, db_pool: Data<DbPool>) -> Result<HttpRe
}

/// Unlock an infra
#[utoipa::path(
tag = "infra",
params(InfraIdParam),
responses(
(status = 204, description = "The infra was unlocked successfully"),
(status = 404, description = "The infra was not found",),
)
)]
#[post("/unlock")]
async fn unlock(infra: Path<i64>, db_pool: Data<DbPool>) -> Result<HttpResponse> {
set_locked(*infra, false, db_pool.into_inner()).await?;
async fn unlock(infra: Path<InfraIdParam>, db_pool: Data<DbPool>) -> Result<HttpResponse> {
set_locked(infra.infra_id, false, db_pool.into_inner()).await?;
Ok(HttpResponse::NoContent().finish())
}

Expand Down
24 changes: 12 additions & 12 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ const injectedRtkApi = api
query: (queryArg) => ({ url: `/infra/${queryArg.id}/switch_types/` }),
providesTags: ['infra'],
}),
postInfraByIdUnlock: build.mutation<
PostInfraByIdUnlockApiResponse,
PostInfraByIdUnlockApiArg
>({
query: (queryArg) => ({ url: `/infra/${queryArg.id}/unlock/`, method: 'POST' }),
invalidatesTags: ['infra'],
}),
getInfraByIdVoltages: build.query<
GetInfraByIdVoltagesApiResponse,
GetInfraByIdVoltagesApiArg
Expand Down Expand Up @@ -304,6 +297,13 @@ const injectedRtkApi = api
}),
providesTags: ['infra', 'routes'],
}),
postInfraByInfraIdUnlock: build.mutation<
PostInfraByInfraIdUnlockApiResponse,
PostInfraByInfraIdUnlockApiArg
>({
query: (queryArg) => ({ url: `/infra/${queryArg.infraId}/unlock/`, method: 'POST' }),
invalidatesTags: ['infra'],
}),
getLayersLayerByLayerSlugMvtAndViewSlug: build.query<
GetLayersLayerByLayerSlugMvtAndViewSlugApiResponse,
GetLayersLayerByLayerSlugMvtAndViewSlugApiArg
Expand Down Expand Up @@ -1144,11 +1144,6 @@ export type GetInfraByIdSwitchTypesApiArg = {
/** infra id */
id: number;
};
export type PostInfraByIdUnlockApiResponse = unknown;
export type PostInfraByIdUnlockApiArg = {
/** infra id */
id: number;
};
export type GetInfraByIdVoltagesApiResponse = /** status 200 Voltages list */ string[];
export type GetInfraByIdVoltagesApiArg = {
/** Infra ID */
Expand Down Expand Up @@ -1242,6 +1237,11 @@ export type GetInfraByInfraIdRoutesAndWaypointTypeWaypointIdApiArg = {
/** Waypoint ID */
waypointId: string;
};
export type PostInfraByInfraIdUnlockApiResponse = unknown;
export type PostInfraByInfraIdUnlockApiArg = {
/** An existing infra ID */
infraId: number;
};
export type GetLayersLayerByLayerSlugMvtAndViewSlugApiResponse =
/** status 200 Successful Response */ {
attribution: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function ActionsBar({ infra, isFocused, setIsFocused, inputValue
const dispatch = useAppDispatch();

const [lockInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdLock.useMutation();
const [unlockInfra] = osrdEditoastApi.endpoints.postInfraByIdUnlock.useMutation();
const [unlockInfra] = osrdEditoastApi.endpoints.postInfraByInfraIdUnlock.useMutation();
const [getRailjson] = osrdEditoastApi.endpoints.getInfraByIdRailjson.useLazyQuery();
const [cloneInfra] = osrdEditoastApi.endpoints.postInfraByIdClone.useMutation();
const [updateInfra] = osrdEditoastApi.endpoints.putInfraById.useMutation();
Expand All @@ -37,7 +37,7 @@ export default function ActionsBar({ infra, isFocused, setIsFocused, inputValue
await lockInfra({ infraId: infra.id });
}
if (action === InfraLockState.UNLOCK) {
await unlockInfra({ id: infra.id });
await unlockInfra({ infraId: infra.id });
}
} catch (e) {
if (e instanceof Error) {
Expand Down

0 comments on commit be2941a

Please sign in to comment.