Skip to content

Commit

Permalink
editoast: work-schedules: add endpoints for easier edition and viewing
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi Charpentier <[email protected]>
  • Loading branch information
eckter committed Nov 26, 2024
1 parent 460c405 commit 68c3e14
Show file tree
Hide file tree
Showing 7 changed files with 646 additions and 66 deletions.
223 changes: 209 additions & 14 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3095,15 +3095,170 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/WorkScheduleCreateForm'
type: object
description: This structure is used by the post endpoint to create a work schedule
required:
- work_schedule_group_name
- work_schedules
properties:
work_schedule_group_name:
type: string
work_schedules:
type: array
items:
$ref: '#/components/schemas/WorkScheduleItemForm'
required: true
responses:
'201':
description: The id of the created work schedule group
content:
application/json:
schema:
$ref: '#/components/schemas/WorkScheduleCreateResponse'
type: object
required:
- work_schedule_group_id
properties:
work_schedule_group_id:
type: integer
format: int64
/work_schedules/group:
get:
tags:
- work_schedules
responses:
'201':
description: The existing work schedule group ids
content:
application/json:
schema:
type: array
items:
type: integer
format: int64
post:
tags:
- work_schedules
requestBody:
content:
application/json:
schema:
type: object
properties:
work_schedule_group_name:
type: string
nullable: true
required: true
responses:
'200':
description: The id of the created work schedule group
content:
application/json:
schema:
type: object
required:
- work_schedule_group_id
properties:
work_schedule_group_id:
type: integer
format: int64
/work_schedules/group/{id}:
get:
tags:
- work_schedules
parameters:
- name: page
in: query
required: false
schema:
type: integer
format: int64
default: 1
minimum: 1
- name: page_size
in: query
required: false
schema:
type: integer
format: int64
default: 25
nullable: true
minimum: 1
- name: id
in: path
description: A work schedule group ID
required: true
schema:
type: integer
format: int64
- name: ordering
in: query
required: false
schema:
$ref: '#/components/schemas/Ordering'
responses:
'200':
description: The work schedules in the group
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/PaginationStats'
- type: object
required:
- results
properties:
results:
type: array
items:
$ref: '#/components/schemas/WorkSchedule'
'404':
description: Work schedule group not found
put:
tags:
- work_schedules
parameters:
- name: id
in: path
description: A work schedule group ID
required: true
schema:
type: integer
format: int64
requestBody:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/WorkScheduleItemForm'
required: true
responses:
'200':
description: The work schedules have been created
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/WorkSchedule'
'404':
description: Work schedule group not found
delete:
tags:
- work_schedules
parameters:
- name: id
in: path
description: A work schedule group ID
required: true
schema:
type: integer
format: int64
responses:
'204':
description: The work schedule group has been deleted
'404':
description: The work schedule group does not exist
/work_schedules/project_path:
post:
tags:
Expand Down Expand Up @@ -4375,6 +4530,7 @@ components:
- $ref: '#/components/schemas/EditoastTrainScheduleErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastTrainScheduleErrorNotFound'
- $ref: '#/components/schemas/EditoastWorkScheduleErrorNameAlreadyUsed'
- $ref: '#/components/schemas/EditoastWorkScheduleErrorWorkScheduleGroupNotFound'
description: Generated error type for Editoast
discriminator:
propertyName: type
Expand Down Expand Up @@ -5793,6 +5949,30 @@ components:
type: string
enum:
- editoast:work_schedule:NameAlreadyUsed
EditoastWorkScheduleErrorWorkScheduleGroupNotFound:
type: object
required:
- type
- status
- message
properties:
context:
type: object
required:
- id
properties:
id:
type: integer
message:
type: string
status:
type: integer
enum:
- 404
type:
type: string
enum:
- editoast:work_schedule:WorkScheduleGroupNotFound
EffortCurve:
type: object
required:
Expand Down Expand Up @@ -10873,27 +11053,37 @@ components:
type: string
enum:
- Detector
WorkScheduleCreateForm:
WorkSchedule:
type: object
description: This structure is used by the post endpoint to create a work schedule
required:
- work_schedule_group_name
- work_schedules
- id
- start_date_time
- end_date_time
- track_ranges
- obj_id
- work_schedule_type
- work_schedule_group_id
properties:
work_schedule_group_name:
end_date_time:
type: string
format: date-time
id:
type: integer
format: int64
obj_id:
type: string
start_date_time:
type: string
work_schedules:
format: date-time
track_ranges:
type: array
items:
$ref: '#/components/schemas/WorkScheduleItemForm'
WorkScheduleCreateResponse:
type: object
required:
- work_schedule_group_id
properties:
$ref: '#/components/schemas/TrackRange'
work_schedule_group_id:
type: integer
format: int64
work_schedule_type:
$ref: '#/components/schemas/WorkScheduleType'
WorkScheduleItemForm:
type: object
required:
Expand All @@ -10920,6 +11110,11 @@ components:
enum:
- CATENARY
- TRACK
WorkScheduleType:
type: string
enum:
- CATENARY
- TRACK
ZoneUpdate:
type: object
required:
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/models/work_schedules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub enum WorkScheduleType {
Track,
}

#[derive(Debug, Default, Clone, Model)]
#[derive(Debug, Default, Clone, Model, Serialize, Deserialize, ToSchema)]
#[model(table = editoast_models::tables::work_schedule)]
#[model(gen(batch_ops = c, list))]
#[model(gen(batch_ops = cd, list))]
pub struct WorkSchedule {
pub id: i64,
pub start_date_time: DateTime<Utc>,
Expand Down
9 changes: 9 additions & 0 deletions editoast/src/views/operational_studies.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::models::prelude::*;
use crate::models::work_schedules::WorkSchedule;
use crate::models::Project;
use crate::models::Scenario;
use crate::models::Study;
Expand Down Expand Up @@ -58,4 +59,12 @@ impl Ordering {
Ordering::LastModifiedDesc => Scenario::LAST_MODIFICATION.desc(),
}
}

pub fn as_work_schedule_ordering(&self) -> SortSetting<WorkSchedule> {
match *self {
Ordering::NameAsc => WorkSchedule::OBJ_ID.asc(),
Ordering::NameDesc => WorkSchedule::OBJ_ID.desc(),
_ => WorkSchedule::OBJ_ID.asc(),
}
}
}
Loading

0 comments on commit 68c3e14

Please sign in to comment.