mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
enable response error for settings routes
This commit is contained in:
parent
112cd1787c
commit
5c52a1393f
@ -26,15 +26,9 @@ macro_rules! make_setting_route {
|
|||||||
$attr: Some(None),
|
$attr: Some(None),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match data.update_settings(index_uid.into_inner(), settings, false).await {
|
let update_status = data.update_settings(index_uid.into_inner(), settings, false).await?;
|
||||||
Ok(update_status) => {
|
|
||||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_web::post($route, wrap = "Authentication::Private")]
|
#[actix_web::post($route, wrap = "Authentication::Private")]
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
@ -47,27 +41,17 @@ macro_rules! make_setting_route {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
match data.update_settings(index_uid.into_inner(), settings, true).await {
|
let update_status = data.update_settings(index_uid.into_inner(), settings, true).await?;
|
||||||
Ok(update_status) => {
|
|
||||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_web::get($route, wrap = "Authentication::Private")]
|
#[actix_web::get($route, wrap = "Authentication::Private")]
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
data: actix_web::web::Data<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> {
|
||||||
match data.settings(index_uid.into_inner()).await {
|
let settings = data.settings(index_uid.into_inner()).await?;
|
||||||
Ok(settings) => Ok(HttpResponse::Ok().json(settings.$attr)),
|
Ok(HttpResponse::Ok().json(settings.$attr))
|
||||||
Err(e) => {
|
|
||||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -148,17 +132,11 @@ async fn update_all(
|
|||||||
body: web::Json<Settings<Unchecked>>,
|
body: web::Json<Settings<Unchecked>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let settings = body.into_inner().check();
|
let settings = body.into_inner().check();
|
||||||
match data
|
let update_result = data
|
||||||
.update_settings(index_uid.into_inner(), settings, true)
|
.update_settings(index_uid.into_inner(), settings, true)
|
||||||
.await
|
.await?;
|
||||||
{
|
let json = serde_json::json!({ "updateId": update_result.id() });
|
||||||
Ok(update_result) => Ok(
|
Ok(HttpResponse::Accepted().json(json))
|
||||||
HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_result.id() }))
|
|
||||||
),
|
|
||||||
Err(e) => {
|
|
||||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
|
#[get("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
|
||||||
@ -166,12 +144,8 @@ async fn get_all(
|
|||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
match data.settings(index_uid.into_inner()).await {
|
let settings = data.settings(index_uid.into_inner()).await?;
|
||||||
Ok(settings) => Ok(HttpResponse::Ok().json(settings)),
|
Ok(HttpResponse::Ok().json(settings))
|
||||||
Err(e) => {
|
|
||||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
|
#[delete("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
|
||||||
@ -180,15 +154,9 @@ async fn delete_all(
|
|||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let settings = Settings::cleared();
|
let settings = Settings::cleared();
|
||||||
match data
|
let update_result = data
|
||||||
.update_settings(index_uid.into_inner(), settings, false)
|
.update_settings(index_uid.into_inner(), settings, false)
|
||||||
.await
|
.await?;
|
||||||
{
|
let json = serde_json::json!({ "updateId": update_result.id() });
|
||||||
Ok(update_result) => Ok(
|
Ok(HttpResponse::Accepted().json(json))
|
||||||
HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_result.id() }))
|
|
||||||
),
|
|
||||||
Err(e) => {
|
|
||||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,36 +0,0 @@
|
|||||||
use crate::make_update_delete_routes;
|
|
||||||
use actix_web::{web, HttpResponse, get};
|
|
||||||
|
|
||||||
use crate::error::{Error, ResponseError};
|
|
||||||
use crate::helpers::Authentication;
|
|
||||||
use crate::Data;
|
|
||||||
|
|
||||||
#[get(
|
|
||||||
"/indexes/{index_uid}/settings/distinct-attribute",
|
|
||||||
wrap = "Authentication::Private"
|
|
||||||
)]
|
|
||||||
async fn get(
|
|
||||||
data: web::Data<Data>,
|
|
||||||
index_uid: web::Path<String>,
|
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
|
||||||
let index = data
|
|
||||||
.db
|
|
||||||
.load()
|
|
||||||
.open_index(&index_uid.as_ref())
|
|
||||||
.ok_or(Error::index_not_found(&index_uid.as_ref()))?;
|
|
||||||
let reader = data.db.load().main_read_txn()?;
|
|
||||||
let distinct_attribute_id = index.main.distinct_attribute(&reader)?;
|
|
||||||
let schema = index.main.schema(&reader)?;
|
|
||||||
let distinct_attribute = match (schema, distinct_attribute_id) {
|
|
||||||
(Some(schema), Some(id)) => schema.name(id).map(str::to_string),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(distinct_attribute))
|
|
||||||
}
|
|
||||||
|
|
||||||
make_update_delete_routes!(
|
|
||||||
"/indexes/{index_uid}/settings/distinct-attribute",
|
|
||||||
String,
|
|
||||||
distinct_attribute
|
|
||||||
);
|
|
@ -1,23 +0,0 @@
|
|||||||
use crate::make_update_delete_routes;
|
|
||||||
use actix_web::{web, HttpResponse, get};
|
|
||||||
|
|
||||||
use crate::error::{Error, ResponseError};
|
|
||||||
use crate::helpers::Authentication;
|
|
||||||
use crate::Data;
|
|
||||||
|
|
||||||
#[get(
|
|
||||||
"/indexes/{index_uid}/settings/ranking-rules",
|
|
||||||
wrap = "Authentication::Private"
|
|
||||||
)]
|
|
||||||
async fn get(
|
|
||||||
data: web::Data<Data>,
|
|
||||||
index_uid: web::Path<String>,
|
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
make_update_delete_routes!(
|
|
||||||
"/indexes/{index_uid}/settings/ranking-rules",
|
|
||||||
Vec<String>,
|
|
||||||
ranking_rules
|
|
||||||
);
|
|
@ -1,43 +0,0 @@
|
|||||||
use std::collections::BTreeMap;
|
|
||||||
|
|
||||||
use actix_web::{web, HttpResponse, get};
|
|
||||||
use indexmap::IndexMap;
|
|
||||||
|
|
||||||
use crate::error::{Error, ResponseError};
|
|
||||||
use crate::helpers::Authentication;
|
|
||||||
use crate::make_update_delete_routes;
|
|
||||||
use crate::Data;
|
|
||||||
|
|
||||||
#[get(
|
|
||||||
"/indexes/{index_uid}/settings/synonyms",
|
|
||||||
wrap = "Authentication::Private"
|
|
||||||
)]
|
|
||||||
async fn get(
|
|
||||||
data: web::Data<Data>,
|
|
||||||
index_uid: web::Path<String>,
|
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
|
||||||
let index = data
|
|
||||||
.db
|
|
||||||
.load()
|
|
||||||
.open_index(&index_uid.as_ref())
|
|
||||||
.ok_or(Error::index_not_found(&index_uid.as_ref()))?;
|
|
||||||
|
|
||||||
let reader = data.db.load().main_read_txn()?;
|
|
||||||
|
|
||||||
let synonyms_list = index.main.synonyms(&reader)?;
|
|
||||||
|
|
||||||
let mut synonyms = IndexMap::new();
|
|
||||||
let index_synonyms = &index.synonyms;
|
|
||||||
for synonym in synonyms_list {
|
|
||||||
let list = index_synonyms.synonyms(&reader, synonym.as_bytes())?;
|
|
||||||
synonyms.insert(synonym, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(synonyms))
|
|
||||||
}
|
|
||||||
|
|
||||||
make_update_delete_routes!(
|
|
||||||
"/indexes/{index_uid}/settings/synonyms",
|
|
||||||
BTreeMap<String, Vec<String>>,
|
|
||||||
synonyms
|
|
||||||
);
|
|
Loading…
Reference in New Issue
Block a user