diff --git a/editoast/openapi.yaml b/editoast/openapi.yaml index 92450927f9c..7f2dc2dc668 100644 --- a/editoast/openapi.yaml +++ b/editoast/openapi.yaml @@ -2764,7 +2764,9 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/WorkScheduleProjectResponse' + type: array + items: + $ref: '#/components/schemas/WorkScheduleProjection' components: schemas: AddOperation: @@ -9989,17 +9991,14 @@ components: work_schedule_group_id: type: integer format: int64 - WorkScheduleProjectResponse: - type: object - required: - - projections - properties: - projections: - type: array - items: - $ref: '#/components/schemas/WorkScheduleProjection' WorkScheduleProjection: type: object + description: |- + This struct represents the projection of one work_schedule on a path. + it takes the type, start time, end time of the work_schedule + as well as a list of ranges (a, b), + where a and b are the distance of the beginning and end of the track range + relatively to the beginning of the path. required: - type - start_date_time diff --git a/editoast/src/views/work_schedules.rs b/editoast/src/views/work_schedules.rs index 87dc5e4a44a..b93d6fb472d 100644 --- a/editoast/src/views/work_schedules.rs +++ b/editoast/src/views/work_schedules.rs @@ -37,7 +37,6 @@ editoast_common::schemas! { WorkScheduleCreateForm, WorkScheduleCreateResponse, WorkScheduleProjectForm, - WorkScheduleProjectResponse, WorkScheduleProjection, WorkScheduleItemForm, WorkScheduleType, @@ -191,11 +190,11 @@ struct WorkScheduleProjectForm { path_track_ranges: Vec, } -#[derive(Serialize, Deserialize, ToSchema, PartialEq, Debug)] -struct WorkScheduleProjectResponse { - projections: Vec, -} - +/// This struct represents the projection of one work_schedule on a path. +/// it takes the type, start time, end time of the work_schedule +/// as well as a list of ranges (a, b), +/// where a and b are the distance of the beginning and end of the track range +/// relatively to the beginning of the path. #[derive(Serialize, Deserialize, ToSchema, PartialEq, Debug)] struct WorkScheduleProjection { #[serde(rename = "type")] @@ -211,8 +210,8 @@ struct WorkScheduleProjection { request_body = WorkScheduleProjectForm, responses( ( - status = 201, - body = WorkScheduleProjectResponse, + status = 201, + body = Vec, description = "Returns a list of work schedule whose track ranges intersect the given path" ), ) @@ -224,7 +223,7 @@ async fn project( work_schedule_group_id, path_track_ranges, }): Json, -) -> Result> { +) -> Result>> { let authorized = authorizer .check_roles([BuiltinRole::WorkScheduleRead].into()) .await @@ -243,7 +242,7 @@ async fn project( let projections = work_schedules .into_iter() .filter_map(|ws| { - let ws_track_ranges: Vec = ws + let ws_track_ranges: Vec<_> = ws .track_ranges .into_iter() .map(|tr| CoreTrackRange { @@ -269,7 +268,7 @@ async fn project( } }) .collect(); - Ok(Json(WorkScheduleProjectResponse { projections })) + Ok(Json(projections)) } #[cfg(test)] @@ -484,20 +483,20 @@ pub mod test { let work_schedule_project_response = app .fetch(request) .assert_status(StatusCode::OK) - .json_into::(); + .json_into::>(); // THEN - let expected = WorkScheduleProjectResponse { - projections: expected_path_position_ranges - .into_iter() - .enumerate() - .map(|(index, position_ranges)| WorkScheduleProjection { - work_schedule_type: work_schedules[index].work_schedule_type, - start_date_time: work_schedules[index].start_date_time, - end_date_time: work_schedules[index].end_date_time, - path_position_ranges: position_ranges, - }).collect() - }; + let expected: Vec = expected_path_position_ranges + .into_iter() + .enumerate() + .map(|(index, position_ranges)| WorkScheduleProjection { + work_schedule_type: work_schedules[index].work_schedule_type, + start_date_time: work_schedules[index].start_date_time, + end_date_time: work_schedules[index].end_date_time, + path_position_ranges: position_ranges, + }) + .collect(); + assert_eq!(work_schedule_project_response, expected); } } diff --git a/front/src/common/api/generatedEditoastApi.ts b/front/src/common/api/generatedEditoastApi.ts index b6245aa3c6e..7af7a3e2471 100644 --- a/front/src/common/api/generatedEditoastApi.ts +++ b/front/src/common/api/generatedEditoastApi.ts @@ -1491,7 +1491,7 @@ export type PostWorkSchedulesApiArg = { workScheduleCreateForm: WorkScheduleCreateForm; }; export type PostWorkSchedulesProjectApiResponse = - /** status 201 Returns a list of work schedule whose track ranges intersect the given path */ WorkScheduleProjectResponse; + /** status 201 Returns a list of work schedule whose track ranges intersect the given path */ WorkScheduleProjection[]; export type PostWorkSchedulesProjectApiArg = { workScheduleProjectForm: WorkScheduleProjectForm; }; @@ -3052,9 +3052,6 @@ export type WorkScheduleProjection = { start_date_time: string; type: WorkScheduleType; }; -export type WorkScheduleProjectResponse = { - projections: WorkScheduleProjection[]; -}; export type WorkScheduleProjectForm = { path_track_ranges: TrackRange[]; work_schedule_group_id: number;