From a955e04ab6c0b48821f01011d88409e0214a97c4 Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 4 Mar 2021 16:04:12 +0100 Subject: [PATCH] implement clear documents --- src/data/updates.rs | 8 +++----- src/index_controller/mod.rs | 8 ++++++-- src/routes/document.rs | 19 +++++++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/data/updates.rs b/src/data/updates.rs index 775734ac1..a712f4cc6 100644 --- a/src/data/updates.rs +++ b/src/data/updates.rs @@ -34,12 +34,10 @@ impl Data { pub async fn clear_documents( &self, - _index: impl AsRef + Sync + Send + 'static, + index: impl AsRef + Sync + Send + 'static, ) -> anyhow::Result { - todo!() - //let index_controller = self.index_controller.clone(); - //let update = tokio::task::spawn_blocking(move || index_controller.clear_documents(index)).await??; - //Ok(update.into()) + let update = self.index_controller.clear_documents(index.as_ref().to_string()).await?; + Ok(update) } pub async fn delete_documents( diff --git a/src/index_controller/mod.rs b/src/index_controller/mod.rs index 5f00c2540..d790d1d58 100644 --- a/src/index_controller/mod.rs +++ b/src/index_controller/mod.rs @@ -106,8 +106,12 @@ impl IndexController { Ok(status) } - fn clear_documents(&self, index: String) -> anyhow::Result { - todo!() + pub async fn clear_documents(&self, index: String) -> anyhow::Result { + let uuid = self.uuid_resolver.resolve(index).await.unwrap().unwrap(); + let meta = UpdateMeta::ClearDocuments; + let (_, receiver) = mpsc::channel(1); + let status = self.update_handle.update(meta, receiver, uuid).await?; + Ok(status) } pub async fn delete_documents(&self, index: String, document_ids: Vec) -> anyhow::Result { diff --git a/src/routes/document.rs b/src/routes/document.rs index a848ddcc4..43d88e4b9 100644 --- a/src/routes/document.rs +++ b/src/routes/document.rs @@ -250,14 +250,13 @@ async fn clear_all_documents( data: web::Data, path: web::Path, ) -> Result { - todo!() - //match data.clear_documents(path.index_uid.clone()).await { - //Ok(update) => { - //let json = serde_json::to_string(&update).unwrap(); - //Ok(HttpResponse::Ok().body(json)) - //} - //Err(e) => { - //Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) - //} - //} + match data.clear_documents(path.index_uid.clone()).await { + Ok(update) => { + let json = serde_json::to_string(&update).unwrap(); + Ok(HttpResponse::Ok().body(json)) + } + Err(e) => { + Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) + } + } }