Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anisometropie committed Sep 13, 2024
1 parent 28aa52f commit 1d11333
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
19 changes: 9 additions & 10 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,9 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/WorkScheduleProjectResponse'
type: array
items:
$ref: '#/components/schemas/WorkScheduleProjection'
components:
schemas:
AddOperation:
Expand Down Expand Up @@ -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
Expand Down
45 changes: 22 additions & 23 deletions editoast/src/views/work_schedules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ editoast_common::schemas! {
WorkScheduleCreateForm,
WorkScheduleCreateResponse,
WorkScheduleProjectForm,
WorkScheduleProjectResponse,
WorkScheduleProjection,
WorkScheduleItemForm,
WorkScheduleType,
Expand Down Expand Up @@ -191,11 +190,11 @@ struct WorkScheduleProjectForm {
path_track_ranges: Vec<CoreTrackRange>,
}

#[derive(Serialize, Deserialize, ToSchema, PartialEq, Debug)]
struct WorkScheduleProjectResponse {
projections: Vec<WorkScheduleProjection>,
}

/// 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")]
Expand All @@ -211,8 +210,8 @@ struct WorkScheduleProjection {
request_body = WorkScheduleProjectForm,
responses(
(
status = 201,
body = WorkScheduleProjectResponse,
status = 201,
body = Vec<WorkScheduleProjection>,
description = "Returns a list of work schedule whose track ranges intersect the given path"
),
)
Expand All @@ -224,7 +223,7 @@ async fn project(
work_schedule_group_id,
path_track_ranges,
}): Json<WorkScheduleProjectForm>,
) -> Result<Json<WorkScheduleProjectResponse>> {
) -> Result<Json<Vec<WorkScheduleProjection>>> {
let authorized = authorizer
.check_roles([BuiltinRole::WorkScheduleRead].into())
.await
Expand All @@ -243,7 +242,7 @@ async fn project(
let projections = work_schedules
.into_iter()
.filter_map(|ws| {
let ws_track_ranges: Vec<CoreTrackRange> = ws
let ws_track_ranges: Vec<_> = ws
.track_ranges
.into_iter()
.map(|tr| CoreTrackRange {
Expand All @@ -269,7 +268,7 @@ async fn project(
}
})
.collect();
Ok(Json(WorkScheduleProjectResponse { projections }))
Ok(Json(projections))
}

#[cfg(test)]
Expand Down Expand Up @@ -484,20 +483,20 @@ pub mod test {
let work_schedule_project_response = app
.fetch(request)
.assert_status(StatusCode::OK)
.json_into::<WorkScheduleProjectResponse>();
.json_into::<Vec<WorkScheduleProjection>>();

// 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<WorkScheduleProjection> = 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);
}
}
5 changes: 1 addition & 4 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1d11333

Please sign in to comment.