Skip to content

Commit

Permalink
editoast: project work_schedules on path endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Chanas <[email protected]>
  • Loading branch information
anisometropie committed Sep 17, 2024
1 parent f210693 commit 201a07e
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 5 deletions.
5 changes: 4 additions & 1 deletion editoast/editoast_authz/src/builtin_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum BuiltinRole {

#[strum(serialize = "work_schedule:write")]
WorkScheduleWrite,
#[strum(serialize = "work_schedule:read")]
WorkScheduleRead,

#[strum(serialize = "map:read")]
MapRead,
Expand Down Expand Up @@ -55,7 +57,8 @@ impl BuiltinRoleSet for BuiltinRole {
InfraWrite => vec![InfraRead],
RollingStockCollectionRead => vec![],
RollingStockCollectionWrite => vec![RollingStockCollectionRead],
WorkScheduleWrite => vec![],
WorkScheduleWrite => vec![WorkScheduleRead],
WorkScheduleRead => vec![],
MapRead => vec![],
Stdcm => vec![MapRead],
TimetableRead => vec![],
Expand Down
66 changes: 66 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,72 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/WorkScheduleCreateResponse'
/work_schedules/project_path:
post:
tags:
- work_schedules
requestBody:
content:
application/json:
schema:
type: object
required:
- work_schedule_group_id
- path_track_ranges
properties:
path_track_ranges:
type: array
items:
$ref: '#/components/schemas/TrackRange'
work_schedule_group_id:
type: integer
format: int64
required: true
responses:
'201':
description: Returns a list of work schedules whose track ranges intersect the given path
content:
application/json:
schema:
type: array
items:
type: object
description: Represents the projection of a work schedule on a path.
required:
- type
- start_date_time
- end_date_time
- path_position_ranges
properties:
end_date_time:
type: string
format: date-time
description: The date and time when the work schedule ends.
path_position_ranges:
type: array
items:
type: array
items:
allOf:
- type: integer
format: int64
minimum: 0
- type: integer
format: int64
minimum: 0
description: |-
a list of intervals `(a, b)` that represent the projections of the work schedule track ranges:
- `a` is the distance from the beginning of the path to the beginning of the track range
- `b` is the distance from the beginning of the path to the end of the track range
start_date_time:
type: string
format: date-time
description: The date and time when the work schedule takes effect.
type:
type: string
enum:
- CATENARY
- TRACK
components:
schemas:
AddOperation:
Expand Down
19 changes: 18 additions & 1 deletion editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ use editoast_schemas::primitives::OSRDObject;
use editoast_schemas::rolling_stock::RollingStock;
use editoast_schemas::train_schedule::TrainScheduleBase;
use postgis_diesel::types::LineString;
use serde_json::Value;

use crate::infra_cache::operation::create::apply_create_operation;
use crate::models::prelude::*;
use crate::models::rolling_stock_livery::RollingStockLiveryModel;
use crate::models::timetable::Timetable;
use crate::models::train_schedule::TrainSchedule;
use crate::models::work_schedules::WorkScheduleGroup;
use crate::models::work_schedules::{WorkSchedule, WorkScheduleGroup};
use crate::models::Document;
use crate::models::Infra;
use crate::models::Project;
Expand Down Expand Up @@ -308,3 +309,19 @@ pub async fn create_work_schedule_group(conn: &mut DbConnection) -> WorkSchedule
.await
.expect("Failed to create empty work schedule group")
}

pub async fn create_work_schedules_fixture_set(
conn: &mut DbConnection,
work_schedules: Vec<Changeset<WorkSchedule>>,
) -> (WorkScheduleGroup, Vec<WorkSchedule>) {
let work_schedule_group = create_work_schedule_group(conn).await;
let work_schedules_changesets = work_schedules
.into_iter()
.map(|ws| ws.work_schedule_group_id(work_schedule_group.id))
.collect::<Vec<_>>();
let work_schedules = WorkSchedule::create_batch(conn, work_schedules_changesets)
.await
.expect("Failed to create work test schedules");

(work_schedule_group, work_schedules)
}
Loading

0 comments on commit 201a07e

Please sign in to comment.