Skip to content

Commit e45c644

Browse files
committed
fixup! editoast: add train_schedule object to search endpoint
1 parent 6250bbe commit e45c644

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

editoast/openapi.yaml

+11-18
Original file line numberDiff line numberDiff line change
@@ -9000,16 +9000,13 @@ components:
90009000
- comfort
90019001
- path
90029002
- constraint_distribution
9003-
- speed_limit_tag
90049003
- power_restrictions
90059004
- options
90069005
properties:
90079006
comfort:
9008-
type: integer
9009-
format: int32
9007+
$ref: '#/components/schemas/Comfort'
90109008
constraint_distribution:
9011-
type: integer
9012-
format: int32
9009+
$ref: '#/components/schemas/Distribution'
90139010
id:
90149011
type: integer
90159012
format: int64
@@ -9021,38 +9018,34 @@ components:
90219018
type: array
90229019
items:
90239020
type: string
9021+
nullable: true
90249022
margins:
9025-
type: array
9026-
items:
9027-
type: string
9023+
$ref: '#/components/schemas/Margins'
90289024
options:
9029-
type: array
9030-
items:
9031-
type: string
9025+
$ref: '#/components/schemas/TrainScheduleOptions'
90329026
path:
90339027
type: array
90349028
items:
9035-
type: string
9029+
$ref: '#/components/schemas/PathItem'
90369030
power_restrictions:
90379031
type: array
90389032
items:
9039-
type: string
9033+
$ref: '#/components/schemas/PowerRestrictionItem'
90409034
rolling_stock_name:
90419035
type: string
90429036
schedule:
90439037
type: array
90449038
items:
9045-
type: string
9039+
$ref: '#/components/schemas/ScheduleItem'
90469040
speed_limit_tag:
9047-
type: array
9048-
items:
9049-
type: string
9041+
type: string
9042+
nullable: true
90509043
start_time:
90519044
type: string
9045+
format: date-time
90529046
timetable_id:
90539047
type: integer
90549048
format: int64
9055-
minimum: 0
90569049
train_name:
90579050
type: string
90589051
Side:

editoast/src/views/search.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ use axum::extract::Json;
203203
use axum::extract::Query;
204204
use axum::extract::State;
205205
use axum::Extension;
206+
use chrono::DateTime;
206207
use chrono::NaiveDateTime;
208+
use chrono::Utc;
207209
use diesel::pg::Pg;
208210
use diesel::sql_query;
209211
use diesel::sql_types::Jsonb;
@@ -215,6 +217,13 @@ use editoast_common::geometry::GeoJsonPoint;
215217
use editoast_derive::EditoastError;
216218
use editoast_derive::Search;
217219
use editoast_derive::SearchConfigStore;
220+
use editoast_schemas::train_schedule::Comfort;
221+
use editoast_schemas::train_schedule::Distribution;
222+
use editoast_schemas::train_schedule::Margins;
223+
use editoast_schemas::train_schedule::PathItem;
224+
use editoast_schemas::train_schedule::PowerRestrictionItem;
225+
use editoast_schemas::train_schedule::ScheduleItem;
226+
use editoast_schemas::train_schedule::TrainScheduleOptions;
218227
use editoast_search::query_into_sql;
219228
use editoast_search::SearchConfigStore as _;
220229
use editoast_search::SearchError;
@@ -344,9 +353,8 @@ async fn search(
344353
Json(SearchPayload { object, query, dry }): Json<SearchPayload>,
345354
) -> Result<Json<serde_json::Value>> {
346355
let roles: HashSet<BuiltinRole> = match object.as_str() {
347-
"track" | "operationalpoint" | "signal" | "trainschedule" => {
348-
HashSet::from([BuiltinRole::InfraRead])
349-
}
356+
"track" | "operationalpoint" | "signal" => HashSet::from([BuiltinRole::InfraRead]),
357+
"trainschedule" => HashSet::from([BuiltinRole::TimetableRead]),
350358
"project" | "study" | "scenario" => HashSet::from([BuiltinRole::OpsRead]),
351359
_ => {
352360
return Err(SearchApiError::ObjectType {
@@ -697,33 +705,33 @@ pub(super) struct SearchResultItemTrainSchedule {
697705
#[search(sql = "train_schedule.id")]
698706
id: u64,
699707
#[search(sql = "train_schedule.train_name")]
700-
train_name: String, // useless puisqu'on en a besoin pour la request?
708+
train_name: String,
701709
#[search(sql = "train_schedule.labels")]
702-
labels: Vec<String>,
710+
labels: Vec<Option<String>>,
703711
#[search(sql = "train_schedule.rolling_stock_name")]
704712
rolling_stock_name: String,
705713
#[search(sql = "train_schedule.timetable_id")]
706-
timetable_id: u64, // useless puisqu'on en a besoin pour la request?
714+
timetable_id: i64,
707715
#[search(sql = "train_schedule.start_time")]
708-
start_time: String,
716+
start_time: DateTime<Utc>,
709717
#[search(sql = "train_schedule.schedule")]
710-
schedule: Vec<String>,
718+
schedule: Vec<ScheduleItem>,
711719
#[search(sql = "train_schedule.margins")]
712-
margins: Vec<String>,
720+
margins: Margins,
713721
#[search(sql = "train_schedule.initial_speed")]
714722
initial_speed: f64,
715723
#[search(sql = "train_schedule.comfort")]
716-
comfort: i16,
724+
comfort: Comfort,
717725
#[search(sql = "train_schedule.path")]
718-
path: Vec<String>,
726+
path: Vec<PathItem>,
719727
#[search(sql = "train_schedule.constraint_distribution")]
720-
constraint_distribution: i16,
728+
constraint_distribution: Distribution,
721729
#[search(sql = "train_schedule.speed_limit_tag")]
722-
speed_limit_tag: Vec<String>,
730+
speed_limit_tag: Option<String>,
723731
#[search(sql = "train_schedule.power_restrictions")]
724-
power_restrictions: Vec<String>,
732+
power_restrictions: Vec<PowerRestrictionItem>,
725733
#[search(sql = "train_schedule.options")]
726-
options: Vec<String>,
734+
options: TrainScheduleOptions,
727735
}
728736

729737
/// See [editoast_search::SearchConfigStore::find]

0 commit comments

Comments
 (0)