Skip to content

Commit

Permalink
front: fix pr comments
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <[email protected]>
  • Loading branch information
Wadjetz committed Feb 12, 2025
1 parent ddfa18b commit c1a380c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
41 changes: 33 additions & 8 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4825,8 +4825,9 @@ components:
- $ref: '#/components/schemas/EditoastSpriteErrorsFileNotFound'
- $ref: '#/components/schemas/EditoastSpriteErrorsUnknownSignalingSystem'
- $ref: '#/components/schemas/EditoastStdcmErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastStdcmErrorInvalidConsistLength'
- $ref: '#/components/schemas/EditoastStdcmErrorInvalidConsistMass'
- $ref: '#/components/schemas/EditoastStdcmErrorInvalidPathItems'
- $ref: '#/components/schemas/EditoastStdcmErrorInvalidRequest'
- $ref: '#/components/schemas/EditoastStdcmErrorRollingStockNotFound'
- $ref: '#/components/schemas/EditoastStdcmErrorTimetableNotFound'
- $ref: '#/components/schemas/EditoastStdcmErrorTowedRollingStockNotFound'
Expand Down Expand Up @@ -6019,7 +6020,7 @@ components:
type: string
enum:
- editoast:stdcm_v2:InfraNotFound
EditoastStdcmErrorInvalidPathItems:
EditoastStdcmErrorInvalidConsistLength:
type: object
required:
- type
Expand All @@ -6029,10 +6030,10 @@ components:
context:
type: object
required:
- items
- message
properties:
items:
type: array
message:
type: string
message:
type: string
status:
Expand All @@ -6042,8 +6043,8 @@ components:
type:
type: string
enum:
- editoast:stdcm_v2:InvalidPathItems
EditoastStdcmErrorInvalidRequest:
- editoast:stdcm_v2:InvalidConsistLength
EditoastStdcmErrorInvalidConsistMass:
type: object
required:
- type
Expand All @@ -6066,7 +6067,31 @@ components:
type:
type: string
enum:
- editoast:stdcm_v2:InvalidRequest
- editoast:stdcm_v2:InvalidConsistMass
EditoastStdcmErrorInvalidPathItems:
type: object
required:
- type
- status
- message
properties:
context:
type: object
required:
- items
properties:
items:
type: array
message:
type: string
status:
type: integer
enum:
- 400
type:
type: string
enum:
- editoast:stdcm_v2:InvalidPathItems
EditoastStdcmErrorRollingStockNotFound:
type: object
required:
Expand Down
10 changes: 6 additions & 4 deletions editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ enum StdcmError {
TrainSimulationFail,
#[error("Path items are invalid")]
InvalidPathItems { items: Vec<InvalidPathItem> },
#[error("Invalid request: {message}")]
InvalidRequest { message: String },
#[error("Invalid consist mass: {message}")]
InvalidConsistMass { message: String },
#[error("Invalid consist length: {message}")]
InvalidConsistLength { message: String },
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, IntoParams, ToSchema)]
Expand Down Expand Up @@ -953,7 +955,7 @@ mod tests {

assert_eq!(
stdcm_response.message,
"Invalid request: The total mass must be greater than the sum of the rolling stock masses (900000 kilograms)"
"Invalid consist mass: The total mass must be greater than the sum of the rolling stock masses (900000 kilograms)"
.to_owned()
);
}
Expand Down Expand Up @@ -999,7 +1001,7 @@ mod tests {

assert_eq!(
stdcm_response.message,
"Invalid request: The total length must be greater than the sum of the rolling stock lengths (400 meters)"
"Invalid consist length: The total length must be greater than the sum of the rolling stock lengths (400 meters)"
.to_owned()
);
}
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/timetable/stdcm/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl Request {

if let Some(request_total_mass) = self.total_mass {
if request_total_mass < consist_mass {
return Err(StdcmError::InvalidRequest {
return Err(StdcmError::InvalidConsistMass {
message: format!(
"The total mass must be greater than the sum of the rolling stock masses ({})",
&consist_mass.into_format_args(kilogram, DisplayStyle::Description),
Expand All @@ -353,7 +353,7 @@ impl Request {

if let Some(request_total_length) = self.total_length {
if request_total_length < consist_length {
return Err(StdcmError::InvalidRequest {
return Err(StdcmError::InvalidConsistLength {
message: format!(
"The total length must be greater than the sum of the rolling stock lengths ({})",
&consist_length.into_format_args(meter, DisplayStyle::Description),
Expand Down
3 changes: 2 additions & 1 deletion front/public/locales/en/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@
"TowedRollingStockNotFound": "Towed rolling stock {towed_rolling_stock_id} does not exist",
"TrainSimulationFail": "Train simulation failed",
"TimetableNotFound": "Timetable '{{timetable_id}}' does not exist",
"InvalidRequest": "Invalid request"
"InvalidConsistMass": "Invalid consist mass: '{{message}}'",
"InvalidConsistLength": "Invalid consist length: '{{message}}'"
},
"study": {
"Database": "Internal error (database)",
Expand Down
3 changes: 2 additions & 1 deletion front/public/locales/fr/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@
"TowedRollingStockNotFound": "Matériel roulant remorqué {towed_rolling_stock_id} non trouvé",
"TrainSimulationFail": "Échec de la simulation du train",
"TimetableNotFound": "Grille horaire '{{timetable_id}}' non trouvée",
"InvalidRequest": "Requête invalide"
"InvalidConsistMass": "La masse du convoi est invalide : '{{message}}'",
"InvalidConsistLength": "La longueur du convoi est invalide : '{{message}}'"
},
"study": {
"Database": "Erreur interne (base de données)",
Expand Down

0 comments on commit c1a380c

Please sign in to comment.