Skip to content

Commit 6250bbe

Browse files
committed
editoast: add train_schedule object to search endpoint
Signed-off-by: Ethan Perruzza <[email protected]>
1 parent 0f97f32 commit 6250bbe

File tree

3 files changed

+136
-2
lines changed

3 files changed

+136
-2
lines changed

editoast/openapi.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -8750,6 +8750,7 @@ components:
87508750
- $ref: '#/components/schemas/SearchResultItemProject'
87518751
- $ref: '#/components/schemas/SearchResultItemStudy'
87528752
- $ref: '#/components/schemas/SearchResultItemScenario'
8753+
- $ref: '#/components/schemas/SearchResultItemTrainSchedule'
87538754
description: A search result item that depends on the query's `object`
87548755
SearchResultItemOperationalPoint:
87558756
type: object
@@ -8983,6 +8984,77 @@ components:
89838984
format: int64
89848985
line_name:
89858986
type: string
8987+
SearchResultItemTrainSchedule:
8988+
type: object
8989+
description: A search result item for a query with `object = "trainschedule"`
8990+
required:
8991+
- id
8992+
- train_name
8993+
- labels
8994+
- rolling_stock_name
8995+
- timetable_id
8996+
- start_time
8997+
- schedule
8998+
- margins
8999+
- initial_speed
9000+
- comfort
9001+
- path
9002+
- constraint_distribution
9003+
- speed_limit_tag
9004+
- power_restrictions
9005+
- options
9006+
properties:
9007+
comfort:
9008+
type: integer
9009+
format: int32
9010+
constraint_distribution:
9011+
type: integer
9012+
format: int32
9013+
id:
9014+
type: integer
9015+
format: int64
9016+
minimum: 0
9017+
initial_speed:
9018+
type: number
9019+
format: double
9020+
labels:
9021+
type: array
9022+
items:
9023+
type: string
9024+
margins:
9025+
type: array
9026+
items:
9027+
type: string
9028+
options:
9029+
type: array
9030+
items:
9031+
type: string
9032+
path:
9033+
type: array
9034+
items:
9035+
type: string
9036+
power_restrictions:
9037+
type: array
9038+
items:
9039+
type: string
9040+
rolling_stock_name:
9041+
type: string
9042+
schedule:
9043+
type: array
9044+
items:
9045+
type: string
9046+
speed_limit_tag:
9047+
type: array
9048+
items:
9049+
type: string
9050+
start_time:
9051+
type: string
9052+
timetable_id:
9053+
type: integer
9054+
format: int64
9055+
minimum: 0
9056+
train_name:
9057+
type: string
89869058
Side:
89879059
type: string
89889060
enum:

editoast/src/views/search.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ async fn search(
344344
Json(SearchPayload { object, query, dry }): Json<SearchPayload>,
345345
) -> Result<Json<serde_json::Value>> {
346346
let roles: HashSet<BuiltinRole> = match object.as_str() {
347-
"track" | "operationalpoint" | "signal" => HashSet::from([BuiltinRole::InfraRead]),
347+
"track" | "operationalpoint" | "signal" | "trainschedule" => {
348+
HashSet::from([BuiltinRole::InfraRead])
349+
}
348350
"project" | "study" | "scenario" => HashSet::from([BuiltinRole::OpsRead]),
349351
_ => {
350352
return Err(SearchApiError::ObjectType {
@@ -683,6 +685,47 @@ pub(super) struct SearchResultItemScenario {
683685
tags: Vec<String>,
684686
}
685687

688+
#[derive(Search, Serialize, ToSchema)]
689+
#[search(
690+
table = "train_schedule",
691+
column(name = "timetable_id", data_type = "integer"),
692+
column(name = "train_name", data_type = "string")
693+
)]
694+
#[allow(unused)]
695+
/// A search result item for a query with `object = "trainschedule"`
696+
pub(super) struct SearchResultItemTrainSchedule {
697+
#[search(sql = "train_schedule.id")]
698+
id: u64,
699+
#[search(sql = "train_schedule.train_name")]
700+
train_name: String, // useless puisqu'on en a besoin pour la request?
701+
#[search(sql = "train_schedule.labels")]
702+
labels: Vec<String>,
703+
#[search(sql = "train_schedule.rolling_stock_name")]
704+
rolling_stock_name: String,
705+
#[search(sql = "train_schedule.timetable_id")]
706+
timetable_id: u64, // useless puisqu'on en a besoin pour la request?
707+
#[search(sql = "train_schedule.start_time")]
708+
start_time: String,
709+
#[search(sql = "train_schedule.schedule")]
710+
schedule: Vec<String>,
711+
#[search(sql = "train_schedule.margins")]
712+
margins: Vec<String>,
713+
#[search(sql = "train_schedule.initial_speed")]
714+
initial_speed: f64,
715+
#[search(sql = "train_schedule.comfort")]
716+
comfort: i16,
717+
#[search(sql = "train_schedule.path")]
718+
path: Vec<String>,
719+
#[search(sql = "train_schedule.constraint_distribution")]
720+
constraint_distribution: i16,
721+
#[search(sql = "train_schedule.speed_limit_tag")]
722+
speed_limit_tag: Vec<String>,
723+
#[search(sql = "train_schedule.power_restrictions")]
724+
power_restrictions: Vec<String>,
725+
#[search(sql = "train_schedule.options")]
726+
options: Vec<String>,
727+
}
728+
686729
/// See [editoast_search::SearchConfigStore::find]
687730
#[derive(SearchConfigStore)]
688731
#[search_config_store(
@@ -692,5 +735,6 @@ pub(super) struct SearchResultItemScenario {
692735
object(name = "project", config = SearchResultItemProject),
693736
object(name = "study", config = SearchResultItemStudy),
694737
object(name = "scenario", config = SearchResultItemScenario),
738+
object(name = "trainschedule", config = SearchResultItemTrainSchedule),
695739
)]
696740
pub struct SearchConfigFinder;

front/src/common/api/generatedEditoastApi.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -2846,13 +2846,31 @@ export type SearchResultItemScenario = {
28462846
tags: string[];
28472847
trains_count: number;
28482848
};
2849+
export type SearchResultItemTrainSchedule = {
2850+
comfort: number;
2851+
constraint_distribution: number;
2852+
id: number;
2853+
initial_speed: number;
2854+
labels: string[];
2855+
margins: string[];
2856+
options: string[];
2857+
path: string[];
2858+
power_restrictions: string[];
2859+
rolling_stock_name: string;
2860+
schedule: string[];
2861+
speed_limit_tag: string[];
2862+
start_time: string;
2863+
timetable_id: number;
2864+
train_name: string;
2865+
};
28492866
export type SearchResultItem =
28502867
| SearchResultItemTrack
28512868
| SearchResultItemOperationalPoint
28522869
| SearchResultItemSignal
28532870
| SearchResultItemProject
28542871
| SearchResultItemStudy
2855-
| SearchResultItemScenario;
2872+
| SearchResultItemScenario
2873+
| SearchResultItemTrainSchedule;
28562874
export type SearchQuery = boolean | number | number | string | (SearchQuery | null)[];
28572875
export type SearchPayload = {
28582876
/** Whether to return the SQL query instead of executing it

0 commit comments

Comments
 (0)