mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
Merge #104
104: Update all the response format (issue #64) r=MarinPostma a=irevoire closes #64 Co-authored-by: Irevoire <tamo@meilisearch.com> Co-authored-by: tamo <tamo@meilisearch.com>
This commit is contained in:
commit
6cb8052d3d
8 changed files with 59 additions and 33 deletions
|
@ -43,6 +43,9 @@ pub struct Settings {
|
|||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub ranking_rules: Option<Option<Vec<String>>>,
|
||||
|
||||
// TODO we are missing the stopWords, synonyms and distinctAttribute for the GET settings
|
||||
// request
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
|
|
|
@ -84,7 +84,9 @@ async fn delete_document(
|
|||
.delete_documents(path.index_uid.clone(), vec![path.document_id.clone()])
|
||||
.await
|
||||
{
|
||||
Ok(result) => Ok(HttpResponse::Ok().json(result)),
|
||||
Ok(update_status) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
@ -119,7 +121,7 @@ async fn get_all_documents(
|
|||
)
|
||||
.await
|
||||
{
|
||||
Ok(docs) => Ok(HttpResponse::Ok().json(docs)),
|
||||
Ok(documents) => Ok(HttpResponse::Ok().json(documents)),
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
@ -133,6 +135,7 @@ struct UpdateDocumentsQuery {
|
|||
}
|
||||
|
||||
/// Route used when the payload type is "application/json"
|
||||
/// Used to add or replace documents
|
||||
#[post("/indexes/{index_uid}/documents", wrap = "Authentication::Private")]
|
||||
async fn add_documents(
|
||||
data: web::Data<Data>,
|
||||
|
@ -151,7 +154,9 @@ async fn add_documents(
|
|||
.await;
|
||||
|
||||
match addition_result {
|
||||
Ok(update) => Ok(HttpResponse::Ok().json(update)),
|
||||
Ok(update_status) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
@ -200,7 +205,9 @@ async fn update_documents(
|
|||
.await;
|
||||
|
||||
match addition_result {
|
||||
Ok(update) => Ok(HttpResponse::Ok().json(update)),
|
||||
Ok(update) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
@ -226,20 +233,25 @@ async fn delete_documents(
|
|||
.collect();
|
||||
|
||||
match data.delete_documents(path.index_uid.clone(), ids).await {
|
||||
Ok(result) => Ok(HttpResponse::Ok().json(result)),
|
||||
Ok(update_status) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// delete all documents
|
||||
#[delete("/indexes/{index_uid}/documents", wrap = "Authentication::Private")]
|
||||
async fn clear_all_documents(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<IndexParam>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
match data.clear_documents(path.index_uid.clone()).await {
|
||||
Ok(update) => Ok(HttpResponse::Ok().json(update)),
|
||||
Ok(update_status) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ macro_rules! make_setting_route {
|
|||
..Default::default()
|
||||
};
|
||||
match data.update_settings(index_uid.into_inner(), settings, false).await {
|
||||
Ok(update_status) => Ok(HttpResponse::Ok().json(update_status)),
|
||||
Ok(update_status) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
@ -46,7 +48,9 @@ macro_rules! make_setting_route {
|
|||
};
|
||||
|
||||
match data.update_settings(index_uid.into_inner(), settings, true).await {
|
||||
Ok(update_status) => Ok(HttpResponse::Ok().json(update_status)),
|
||||
Ok(update_status) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
@ -131,7 +135,9 @@ async fn update_all(
|
|||
.update_settings(index_uid.into_inner(), body.into_inner(), true)
|
||||
.await
|
||||
{
|
||||
Ok(update_result) => Ok(HttpResponse::Accepted().json(update_result)),
|
||||
Ok(update_result) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_result.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
@ -161,7 +167,9 @@ async fn delete_all(
|
|||
.update_settings(index_uid.into_inner(), settings, false)
|
||||
.await
|
||||
{
|
||||
Ok(update_result) => Ok(HttpResponse::Accepted().json(update_result)),
|
||||
Ok(update_result) => {
|
||||
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_result.id() })))
|
||||
}
|
||||
Err(e) => {
|
||||
Ok(HttpResponse::BadRequest().json(serde_json::json!({ "error": e.to_string() })))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue