Skip to content

Commit

Permalink
editoast: project work_schedules on path endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
anisometropie committed Sep 11, 2024
1 parent ef349bf commit e4f583d
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 6 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
72 changes: 72 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,23 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/WorkScheduleCreateResponse'
/work_schedules/project:
post:
tags:
- work_schedules
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/WorkScheduleProjectForm'
required: true
responses:
'201':
description: Returns a list of work schedule whose track ranges intersect the given path
content:
application/json:
schema:
$ref: '#/components/schemas/WorkScheduleProjectResponse'
components:
schemas:
AddOperation:
Expand Down Expand Up @@ -9959,6 +9976,61 @@ components:
enum:
- CATENARY
- TRACK
WorkScheduleProjectForm:
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
WorkScheduleProjectResponse:
type: object
required:
- projections
properties:
projections:
type: array
items:
$ref: '#/components/schemas/WorkScheduleProjection'
WorkScheduleProjection:
type: object
required:
- type
- start_date_time
- end_date_time
- path_position_ranges
properties:
end_date_time:
type: string
format: date-time
path_position_ranges:
type: array
items:
type: array
items:
allOf:
- type: integer
format: int64
minimum: 0
- type: integer
format: int64
minimum: 0
start_date_time:
type: string
format: date-time
type:
$ref: '#/components/schemas/WorkScheduleType'
WorkScheduleType:
type: string
enum:
- CATENARY
- TRACK
ZoneUpdate:
type: object
required:
Expand Down
28 changes: 27 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 All @@ -29,6 +30,7 @@ use crate::models::Study;
use crate::models::Tags;
use crate::views::rolling_stock::form::RollingStockForm;
use crate::views::train_schedule::TrainScheduleForm;
use crate::views::work_schedules::WorkScheduleItemForm;
use crate::ElectricalProfileSet;

pub fn project_changeset(name: &str) -> Changeset<Project> {
Expand Down Expand Up @@ -308,3 +310,27 @@ pub async fn create_work_schedule_group(conn: &mut DbConnection) -> WorkSchedule
.await
.expect("Failed to create empty work schedule group")
}

pub struct WorkSchedulesFixtureSet {
pub work_schedule_group: WorkScheduleGroup,
pub work_schedules: Vec<WorkSchedule>,
}

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

WorkSchedulesFixtureSet {
work_schedule_group,
work_schedules,
}
}
Loading

0 comments on commit e4f583d

Please sign in to comment.