mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-19 01:18:31 +08:00
update settings routes
This commit is contained in:
parent
1e9f374ff8
commit
549b489c8a
@ -1,7 +1,7 @@
|
|||||||
use actix_web::{delete, get, post, web, HttpResponse};
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
use actix_web::{web, HttpResponse};
|
||||||
|
|
||||||
use crate::helpers::Authentication;
|
use crate::extractors::authentication::{GuardedData, policies::*};
|
||||||
use crate::index::Settings;
|
use crate::index::Settings;
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
use crate::{error::ResponseError, index::Unchecked};
|
use crate::{error::ResponseError, index::Unchecked};
|
||||||
@ -11,16 +11,15 @@ macro_rules! make_setting_route {
|
|||||||
($route:literal, $type:ty, $attr:ident, $camelcase_attr:literal) => {
|
($route:literal, $type:ty, $attr:ident, $camelcase_attr:literal) => {
|
||||||
mod $attr {
|
mod $attr {
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use actix_web::{web, HttpResponse};
|
use actix_web::{web, HttpResponse, Resource};
|
||||||
|
|
||||||
use crate::data;
|
use crate::data;
|
||||||
use crate::error::ResponseError;
|
use crate::error::ResponseError;
|
||||||
use crate::helpers::Authentication;
|
|
||||||
use crate::index::Settings;
|
use crate::index::Settings;
|
||||||
|
use crate::extractors::authentication::{GuardedData, policies::*};
|
||||||
|
|
||||||
#[actix_web::delete($route, wrap = "Authentication::Private")]
|
async fn delete(
|
||||||
pub async fn delete(
|
data: GuardedData<Private, data::Data>,
|
||||||
data: web::Data<data::Data>,
|
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
use crate::index::Settings;
|
use crate::index::Settings;
|
||||||
@ -33,9 +32,8 @@ macro_rules! make_setting_route {
|
|||||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::post($route, wrap = "Authentication::Private")]
|
async fn update(
|
||||||
pub async fn update(
|
data: GuardedData<Private, data::Data>,
|
||||||
data: actix_web::web::Data<data::Data>,
|
|
||||||
index_uid: actix_web::web::Path<String>,
|
index_uid: actix_web::web::Path<String>,
|
||||||
body: actix_web::web::Json<Option<$type>>,
|
body: actix_web::web::Json<Option<$type>>,
|
||||||
) -> std::result::Result<HttpResponse, ResponseError> {
|
) -> std::result::Result<HttpResponse, ResponseError> {
|
||||||
@ -49,9 +47,8 @@ macro_rules! make_setting_route {
|
|||||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::get($route, wrap = "Authentication::Private")]
|
async fn get(
|
||||||
pub async fn get(
|
data: GuardedData<Private, data::Data>,
|
||||||
data: actix_web::web::Data<data::Data>,
|
|
||||||
index_uid: actix_web::web::Path<String>,
|
index_uid: actix_web::web::Path<String>,
|
||||||
) -> std::result::Result<HttpResponse, ResponseError> {
|
) -> std::result::Result<HttpResponse, ResponseError> {
|
||||||
let settings = data.settings(index_uid.into_inner()).await?;
|
let settings = data.settings(index_uid.into_inner()).await?;
|
||||||
@ -60,6 +57,13 @@ macro_rules! make_setting_route {
|
|||||||
let val = json[$camelcase_attr].take();
|
let val = json[$camelcase_attr].take();
|
||||||
Ok(HttpResponse::Ok().json(val))
|
Ok(HttpResponse::Ok().json(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resources() -> Resource {
|
||||||
|
Resource::new($route)
|
||||||
|
.route(web::get().to(get))
|
||||||
|
.route(web::post().to(update))
|
||||||
|
.route(web::delete().to(delete))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -117,14 +121,11 @@ macro_rules! create_services {
|
|||||||
($($mod:ident),*) => {
|
($($mod:ident),*) => {
|
||||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg
|
cfg
|
||||||
.service(update_all)
|
.service(web::resource("/indexes/{index_uid}/settings")
|
||||||
.service(get_all)
|
.route(web::post().to(update_all))
|
||||||
.service(delete_all)
|
.route(web::get().to(get_all))
|
||||||
$(
|
.route(web::delete().to(delete_all)))
|
||||||
.service($mod::get)
|
$(.service($mod::resources()))*;
|
||||||
.service($mod::update)
|
|
||||||
.service($mod::delete)
|
|
||||||
)*;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -139,9 +140,8 @@ create_services!(
|
|||||||
ranking_rules
|
ranking_rules
|
||||||
);
|
);
|
||||||
|
|
||||||
#[post("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
|
|
||||||
async fn update_all(
|
async fn update_all(
|
||||||
data: web::Data<Data>,
|
data: GuardedData<Private, Data>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
body: web::Json<Settings<Unchecked>>,
|
body: web::Json<Settings<Unchecked>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
@ -154,9 +154,8 @@ async fn update_all(
|
|||||||
Ok(HttpResponse::Accepted().json(json))
|
Ok(HttpResponse::Accepted().json(json))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
|
|
||||||
async fn get_all(
|
async fn get_all(
|
||||||
data: web::Data<Data>,
|
data: GuardedData<Private, Data>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let settings = data.settings(index_uid.into_inner()).await?;
|
let settings = data.settings(index_uid.into_inner()).await?;
|
||||||
@ -164,9 +163,8 @@ async fn get_all(
|
|||||||
Ok(HttpResponse::Ok().json(settings))
|
Ok(HttpResponse::Ok().json(settings))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
|
|
||||||
async fn delete_all(
|
async fn delete_all(
|
||||||
data: web::Data<Data>,
|
data: GuardedData<Private, Data>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let settings = Settings::cleared();
|
let settings = Settings::cleared();
|
||||||
|
Loading…
Reference in New Issue
Block a user