From df066f43218a9860089c165bd042f2a1b38621d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 6 Nov 2019 11:18:36 +0100 Subject: [PATCH] Introduce a new add or update documents PUT route --- meilidb-http/src/routes/document.rs | 16 ++++++++++++++-- meilidb-http/src/routes/mod.rs | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/meilidb-http/src/routes/document.rs b/meilidb-http/src/routes/document.rs index a627b2195..289fb31ae 100644 --- a/meilidb-http/src/routes/document.rs +++ b/meilidb-http/src/routes/document.rs @@ -151,7 +151,7 @@ fn infered_schema(document: &IndexMap) -> Option) -> SResult { +async fn update_multiple_documents(mut ctx: Context, is_partial: bool) -> SResult { ctx.is_allowed(DocumentsWrite)?; if !ctx.state().accept_updates() { @@ -179,7 +179,11 @@ pub async fn add_or_update_multiple_documents(mut ctx: Context) -> SResult } } - let mut document_addition = index.documents_addition(); + let mut document_addition = if is_partial { + index.documents_partial_addition() + } else { + index.documents_addition() + }; for document in data { document_addition.update_document(document); @@ -197,6 +201,14 @@ pub async fn add_or_update_multiple_documents(mut ctx: Context) -> SResult .into_response()) } +pub async fn add_or_replace_multiple_documents(ctx: Context) -> SResult { + update_multiple_documents(ctx, false).await +} + +pub async fn add_or_update_multiple_documents(ctx: Context) -> SResult { + update_multiple_documents(ctx, true).await +} + pub async fn delete_multiple_documents(mut ctx: Context) -> SResult { ctx.is_allowed(DocumentsWrite)?; if !ctx.state().accept_updates() { diff --git a/meilidb-http/src/routes/mod.rs b/meilidb-http/src/routes/mod.rs index 7bb56ab21..efcf5d4f4 100644 --- a/meilidb-http/src/routes/mod.rs +++ b/meilidb-http/src/routes/mod.rs @@ -37,7 +37,8 @@ pub fn load_routes(app: &mut tide::App) { router .at("/") .get(document::browse_documents) - .post(document::add_or_update_multiple_documents) + .post(document::add_or_replace_multiple_documents) + .put(document::add_or_update_multiple_documents) .delete(document::clear_all_documents); router.at("/:identifier").nest(|router| {