From 01b09c065b29da38ce78e25b75bf1becc9e58df8 Mon Sep 17 00:00:00 2001 From: marin postma Date: Thu, 24 Jun 2021 19:02:28 +0200 Subject: [PATCH] change route to service --- meilisearch-http/src/lib.rs | 4 ++-- meilisearch-http/src/routes/document.rs | 30 ++++++++++++------------- meilisearch-http/src/routes/dump.rs | 4 ++-- meilisearch-http/src/routes/health.rs | 2 +- meilisearch-http/src/routes/index.rs | 12 +++++----- meilisearch-http/src/routes/key.rs | 2 +- meilisearch-http/src/routes/stats.rs | 6 ++--- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index ffdf62eb7..0eb61f84c 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -90,13 +90,13 @@ pub fn dashboard(config: &mut web::ServiceConfig, enable_frontend: bool) { } config.service(scope); } else { - config.route("/", web::get().to(routes::running)); + config.service(web::resource("/").route(web::get().to(routes::running))); } } #[cfg(not(feature = "mini-dashboard"))] pub fn dashboard(config: &mut web::ServiceConfig, _enable_frontend: bool) { - config.route("/", web::get().to(routes::running)); + config.service(web::resource("/").route(web::get().to(routes::running))); } #[macro_export] diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index abea85ed6..817f624d0 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -38,21 +38,21 @@ struct DocumentParam { pub fn services(cfg: &mut web::ServiceConfig) { cfg.service( - web::resource("/indexes/{index_uid}/documents") - .route(web::get().to(get_all_documents)) - .route(web::post().guard(guard_json).to(add_documents)) - .route(web::put().guard(guard_json).to(update_documents)) - .route(web::delete().to(clear_all_documents)), - ) - // this route needs to be before the /documents/{document_id} to match properly - .route( - "/indexes/{index_uid}/documents/delete-batch", - web::post().to(delete_documents), - ) - .service( - web::resource("/indexes/{index_uid}/documents/{document_id}") - .route(web::get().to(get_document)) - .route(web::delete().to(delete_document)), + web::scope("/indexes/{index_uid}/documents") + .service( + web::resource("") + .route(web::get().to(get_all_documents)) + .route(web::post().guard(guard_json).to(add_documents)) + .route(web::put().guard(guard_json).to(update_documents)) + .route(web::delete().to(clear_all_documents)), + ) + // this route needs to be before the /documents/{document_id} to match properly + .service(web::resource("/delete-batch").route(web::post().to(delete_documents))) + .service( + web::resource("/{document_id}") + .route(web::get().to(get_document)) + .route(web::delete().to(delete_document)), + ), ); } diff --git a/meilisearch-http/src/routes/dump.rs b/meilisearch-http/src/routes/dump.rs index f2f276332..e506755a1 100644 --- a/meilisearch-http/src/routes/dump.rs +++ b/meilisearch-http/src/routes/dump.rs @@ -7,8 +7,8 @@ use crate::extractors::authentication::{policies::*, GuardedData}; use crate::Data; pub fn services(cfg: &mut web::ServiceConfig) { - cfg.route("/dumps", web::post().to(create_dump)) - .route("/dumps/{dump_uid}/status", web::get().to(get_dump_status)); + cfg.service(web::resource("/dumps").route(web::post().to(create_dump))) + .service(web::resource("/dumps/{dump_uid}/status").route(web::get().to(get_dump_status))); } async fn create_dump(data: GuardedData) -> Result { diff --git a/meilisearch-http/src/routes/health.rs b/meilisearch-http/src/routes/health.rs index 3c7200200..54237de1a 100644 --- a/meilisearch-http/src/routes/health.rs +++ b/meilisearch-http/src/routes/health.rs @@ -3,7 +3,7 @@ use actix_web::{web, HttpResponse}; use crate::error::ResponseError; pub fn services(cfg: &mut web::ServiceConfig) { - cfg.route("/health", web::get().to(get_health)); + cfg.service(web::resource("/health").route(web::get().to(get_health))); } async fn get_health() -> Result { diff --git a/meilisearch-http/src/routes/index.rs b/meilisearch-http/src/routes/index.rs index 76a6d5da8..eb8da92ed 100644 --- a/meilisearch-http/src/routes/index.rs +++ b/meilisearch-http/src/routes/index.rs @@ -20,13 +20,13 @@ pub fn services(cfg: &mut web::ServiceConfig) { .route(web::put().to(update_index)) .route(web::delete().to(delete_index)), ) - .route( - "/indexes/{index_uid}/updates", - web::get().to(get_all_updates_status), + .service( + web::resource("/indexes/{index_uid}/updates") + .route(web::get().to(get_all_updates_status)) ) - .route( - "/indexes/{index_uid}/updates/{update_id}", - web::get().to(get_update_status), + .service( + web::resource("/indexes/{index_uid}/updates/{update_id}") + .route(web::get().to(get_update_status)) ); } diff --git a/meilisearch-http/src/routes/key.rs b/meilisearch-http/src/routes/key.rs index 1ea400a4d..d47e264be 100644 --- a/meilisearch-http/src/routes/key.rs +++ b/meilisearch-http/src/routes/key.rs @@ -5,7 +5,7 @@ use crate::extractors::authentication::{policies::*, GuardedData}; use crate::Data; pub fn services(cfg: &mut web::ServiceConfig) { - cfg.route("/keys", web::get().to(list)); + cfg.service(web::resource("/keys").route(web::get().to(list))); } #[derive(Serialize)] diff --git a/meilisearch-http/src/routes/stats.rs b/meilisearch-http/src/routes/stats.rs index 33bb482d9..e440ce8ff 100644 --- a/meilisearch-http/src/routes/stats.rs +++ b/meilisearch-http/src/routes/stats.rs @@ -8,9 +8,9 @@ use crate::routes::IndexParam; use crate::Data; pub fn services(cfg: &mut web::ServiceConfig) { - cfg.route("/indexes/{index_uid}/stats", web::get().to(get_index_stats)) - .route("/stats", web::get().to(get_stats)) - .route("/version", web::get().to(get_version)); + cfg.service(web::resource("/indexes/{index_uid}/stats").route(web::get().to(get_index_stats))) + .service(web::resource("/stats").route(web::get().to(get_stats))) + .service(web::resource("/version").route(web::get().to(get_version))); } async fn get_index_stats(