Skip to content

Commit

Permalink
editoast: remove legacy infra routing function
Browse files Browse the repository at this point in the history
  • Loading branch information
leovalais committed Jun 11, 2024
1 parent 4ba956c commit 7573f25
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 107 deletions.
6 changes: 0 additions & 6 deletions editoast/src/views/infra/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::str::FromStr;

use actix_web::dev::HttpServiceFactory;
use actix_web::get;
use actix_web::web::Data;
use actix_web::web::Json as WebJson;
Expand Down Expand Up @@ -29,11 +28,6 @@ crate::routes! {
list_errors,
}

/// Return `/infra/<infra_id>/errors` routes
pub fn routes_v1() -> impl HttpServiceFactory {
list_errors
}

#[derive(Debug, Clone, Deserialize, utoipa::IntoParams)]
#[into_params(parameter_in = Query)]
struct ErrorListQueryParams {
Expand Down
52 changes: 5 additions & 47 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ mod railjson;
mod routes;

use actix_web::delete;
use actix_web::dev::HttpServiceFactory;
use actix_web::get;
use actix_web::post;
use actix_web::put;
use actix_web::web::scope;
use actix_web::web::Data;
use actix_web::web::Json;
use actix_web::web::Path;
Expand All @@ -31,8 +29,6 @@ use thiserror::Error;
use utoipa::IntoParams;
use utoipa::ToSchema;

use self::edition::edit;
use self::edition::split_track_section;
use super::pagination::PaginationStats;
use super::params::List;
use crate::core::infra_loading::InfraLoadRequest;
Expand All @@ -56,6 +52,11 @@ use editoast_schemas::infra::SwitchType;

crate::routes! {
"/infra" => {
list,
create,
refresh,
get_all_voltages,
railjson::routes(),
"/{infra_id}" => {
(
objects::routes(),
Expand All @@ -78,11 +79,6 @@ crate::routes! {
get_voltages,
get_switch_types,
},
list,
create,
refresh,
get_all_voltages,
railjson::routes(),
},
}

Expand All @@ -92,44 +88,6 @@ editoast_common::schemas! {
InfraWithState,
}

/// Return `/infra` routes
pub fn infra_routes() -> impl HttpServiceFactory {
scope("/infra")
.service((
list,
create,
refresh,
get_all_voltages,
railjson::railjson_routes(),
))
.service(
scope("/{infra_id}")
.service((
get,
load,
delete,
clone,
edit,
split_track_section,
put,
lock,
unlock,
get_speed_limit_tags,
get_voltages,
get_switch_types,
))
.service((
errors::routes_v1(),
objects::routes_v1(),
routes::routes(),
pathfinding::routes(),
attached::routes(),
lines::routes(),
auto_fixes::routes(),
)),
)
}

#[derive(Debug, Error, EditoastError)]
#[editoast_error(base_id = "infra")]
pub enum InfraApiError {
Expand Down
6 changes: 0 additions & 6 deletions editoast/src/views/infra/objects.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::collections::HashSet;

use actix_web::dev::HttpServiceFactory;
use actix_web::post;
use actix_web::web::Data;
use actix_web::web::Json;
Expand All @@ -22,11 +21,6 @@ crate::routes! {
get_objects,
}

/// Return `/infra/<infra_id>/objects` routes
pub fn routes_v1() -> impl HttpServiceFactory {
get_objects
}

#[derive(Debug, Error, EditoastError)]
#[editoast_error(base_id = "infra:objects")]
enum GetObjectsErrors {
Expand Down
7 changes: 0 additions & 7 deletions editoast/src/views/infra/railjson.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use actix_web::dev::HttpServiceFactory;
use actix_web::get;
use actix_web::http::header::ContentType;
use actix_web::post;
use actix_web::services;
use actix_web::web::Data;
use actix_web::web::Json;
use actix_web::web::Path;
Expand Down Expand Up @@ -31,11 +29,6 @@ use crate::views::infra::InfraApiError;
use crate::views::infra::InfraIdParam;
use editoast_schemas::primitives::ObjectType;

/// Return `/infra/<infra_id>/railjson` routes
pub fn railjson_routes() -> impl HttpServiceFactory {
services![get_railjson, post_railjson]
}

crate::routes! {
get_railjson,
post_railjson,
Expand Down
72 changes: 31 additions & 41 deletions editoast/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ pub mod work_schedules;
#[cfg(test)]
mod test_app;

use actix_web::dev::HttpServiceFactory;
use actix_web::get;
use actix_web::services;
use actix_web::web::Data;
use actix_web::web::Json;
use diesel::sql_query;
Expand All @@ -41,7 +39,6 @@ use utoipa::ToSchema;

use self::openapi::merge_path_items;
use self::openapi::remove_discriminator;
use self::openapi::Routes;
use crate::client::get_app_version;
use crate::core::version::CoreVersionRequest;
use crate::core::AsCoreRequest;
Expand All @@ -50,62 +47,55 @@ use crate::core::{self};
use crate::error::ErrorDefinition;
use crate::error::Result;
use crate::error::{self};
use crate::generated_data;
use crate::infra_cache::operation;
use crate::models;
use crate::modelsv2;
use crate::modelsv2::DbConnectionPool;
use crate::RedisClient;

// This function is only temporary while our migration to using utoipa is
// still going

fn routes_v2() -> Routes<impl HttpServiceFactory> {
crate::routes! {
(health, version, core_version),
(rolling_stocks::routes(), light_rolling_stocks::routes()),
(pathfinding::routes(), stdcm::routes(), train_schedule::routes()),
(projects::routes(),timetable::routes(), work_schedules::routes()),
documents::routes(),
sprites::routes(),
search::routes(),
electrical_profiles::routes(),
layers::routes(),
infra::routes(),
single_simulation::routes(),
v2::routes()
}
routes()
}

pub fn routes() -> impl HttpServiceFactory {
services![infra::infra_routes(), routes_v2(),]
crate::routes! {
(health, version, core_version),
(rolling_stocks::routes(), light_rolling_stocks::routes()),
(pathfinding::routes(), stdcm::routes(), train_schedule::routes()),
(projects::routes(),timetable::routes(), work_schedules::routes()),
documents::routes(),
sprites::routes(),
search::routes(),
electrical_profiles::routes(),
layers::routes(),
infra::routes(),
single_simulation::routes(),
v2::routes()
}

editoast_common::schemas! {
error::schemas(),
Version,

editoast_common::schemas(),
editoast_schemas::schemas(),
models::schemas(),
modelsv2::schemas(),
core::schemas(),
Version,
pagination::schemas(),
timetable::schemas(),

documents::schemas(),
pathfinding::schemas(),
electrical_profiles::schemas(),
error::schemas(),
generated_data::schemas(),
infra::schemas(),
light_rolling_stocks::schemas(),
operation::schemas(),
operational_studies::schemas(),
pagination::schemas(),
pathfinding::schemas(),
projects::schemas(),
search::schemas(),
train_schedule::schemas(),
rolling_stocks::schemas(),
light_rolling_stocks::schemas(),
electrical_profiles::schemas(),
infra::schemas(),
search::schemas(),
single_simulation::schemas(),
timetable::schemas(),
train_schedule::schemas(),
v2::schemas(),
work_schedules::schemas(),
editoast_common::schemas(),
operation::schemas(),
editoast_schemas::schemas(),
crate::generated_data::schemas(),
}

#[derive(OpenApi)]
Expand Down Expand Up @@ -258,7 +248,7 @@ impl OpenApiRoot {
}

fn insert_routes(openapi: &mut utoipa::openapi::OpenApi) {
let routes = routes_v2();
let routes = routes();
for (path, path_item) in routes.paths.into_flat_path_list() {
debug!("processing {path}");
if openapi.paths.paths.contains_key(&path) {
Expand Down

0 comments on commit 7573f25

Please sign in to comment.