Skip to content

Commit

Permalink
editoast: set serde_qs to non strict for simulation summary endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
flomonster committed May 23, 2024
1 parent fd6a65c commit 851a10f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
25 changes: 25 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ components:
- $ref: '#/components/schemas/EditoastTrainScheduleErrorUnsimulatedTrainSchedule'
- $ref: '#/components/schemas/EditoastTrainScheduleErrorBatchTrainScheduleNotFound'
- $ref: '#/components/schemas/EditoastTrainScheduleErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastTrainScheduleErrorInvalidQueryParams'
- $ref: '#/components/schemas/EditoastTrainScheduleErrorNotFound'
- $ref: '#/components/schemas/EditoastTypeCheckErrorArgMissing'
- $ref: '#/components/schemas/EditoastTypeCheckErrorArgTypeMismatch'
Expand Down Expand Up @@ -2735,6 +2736,30 @@ components:
- status
- message
type: object
EditoastTrainScheduleErrorInvalidQueryParams:
properties:
context:
properties:
message:
type: string
required:
- message
type: object
message:
type: string
status:
enum:
- 400
type: integer
type:
enum:
- editoast:train_schedule_v2:InvalidQueryParams
type: string
required:
- type
- status
- message
type: object
EditoastTrainScheduleErrorNoSimulation:
properties:
context:
Expand Down
16 changes: 14 additions & 2 deletions editoast/src/views/v2/train_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use std::hash::Hasher;
use std::sync::Arc;

use actix_web::web::{Data, Json, Path, Query};
use actix_web::HttpRequest;
use actix_web::{delete, get, put, HttpResponse};
use editoast_derive::EditoastError;
use editoast_schemas::train_schedule::TrainScheduleBase;
use itertools::Itertools;
use serde::Deserialize;
use serde::Serialize;
use serde_qs::actix::QsQuery;
use serde_qs::Config;
use thiserror::Error;
use tracing::info;
use utoipa::IntoParams;
Expand Down Expand Up @@ -92,6 +94,9 @@ pub enum TrainScheduleError {
#[error("Infra '{infra_id}', could not be found")]
#[editoast_error(status = 404)]
InfraNotFound { infra_id: i64 },
#[error("Invalid query params '{message}'")]
#[editoast_error(status = 400)]
InvalidQueryParams { message: String },
}

#[derive(IntoParams, Deserialize)]
Expand Down Expand Up @@ -527,10 +532,17 @@ enum SimulationSummaryResult {
pub async fn simulation_summary(
db_pool: Data<DbConnectionPool>,
redis_client: Data<RedisClient>,
params: QsQuery<SimulationBatchParams>,
req: HttpRequest,
core: Data<CoreClient>,
) -> Result<Json<HashMap<i64, SimulationSummaryResult>>> {
let query_props = params.into_inner();
// TODO: Stop using serde_qs and move the query params to the body
let config = Config::new(5, false);
let query_props: SimulationBatchParams =
config.deserialize_str(req.query_string()).map_err(|e| {
TrainScheduleError::InvalidQueryParams {
message: e.to_string(),
}
})?;
let infra_id = query_props.infra;
let conn = &mut db_pool.clone().get().await?;
let db_pool = db_pool.into_inner();
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 @@ -183,7 +183,8 @@
"train_schedule_v2": {
"BatchTrainScheduleNotFound": "'{{number}}' train schedule(s) could not be found",
"NotFound": "Train Schedule '{{train_schedule_id}}' could not be found",
"InfraNotFound": "Infrastructure '{{infra_id}}' could not be found"
"InfraNotFound": "Infrastructure '{{infra_id}}' could not be found",
"InvalidQueryparams": "Invalid query params '{{message}}'"
},
"url": {
"InvalidUrl": "Invalid url '{{url}}'"
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 @@ -185,7 +185,8 @@
"train_schedule_v2": {
"BatchTrainScheduleNotFound": "'{{number}}' circulation(s) n'ont pas pu être trouvée(s)",
"NotFound": "Circulation '{{train_schedule_id}}' non trouvée",
"InfraNotFound": "Infrastructure '{{infra_id}}' non trouvée"
"InfraNotFound": "Infrastructure '{{infra_id}}' non trouvée",
"InvalidQueryparams": "Paramètres de la requête invalides '{{message}}'"
},
"url": {
"InvalidUrl": "Url invalide '{{url}}'"
Expand Down

0 comments on commit 851a10f

Please sign in to comment.