implement delete single document

This commit is contained in:
mpostma 2021-02-13 10:44:20 +01:00
parent c317af58bc
commit 28b9c158b1
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
4 changed files with 22 additions and 15 deletions

View file

@ -30,8 +30,8 @@ type Document = IndexMap<String, Value>;
#[derive(Deserialize)]
struct DocumentParam {
_index_uid: String,
_document_id: String,
index_uid: String,
document_id: String,
}
pub fn services(cfg: &mut web::ServiceConfig) {
@ -60,10 +60,19 @@ async fn get_document(
wrap = "Authentication::Private"
)]
async fn delete_document(
_data: web::Data<Data>,
_path: web::Path<DocumentParam>,
data: web::Data<Data>,
path: web::Path<DocumentParam>,
) -> Result<HttpResponse, ResponseError> {
todo!()
match data.delete_documents(path.index_uid.clone(), vec![path.document_id.clone()]).await {
Ok(result) => {
let json = serde_json::to_string(&result).unwrap();
Ok(HttpResponse::Ok().body(json))
}
Err(e) => {
error!("{}", e);
unimplemented!()
}
}
}
#[derive(Deserialize)]
@ -166,10 +175,10 @@ async fn delete_documents(
) -> Result<HttpResponse, ResponseError> {
let ids = body
.iter()
.map(ToString::to_string)
.map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string()))
.collect();
match data.delete_documents(&path.index_uid, ids).await {
match data.delete_documents(path.index_uid.clone(), ids).await {
Ok(result) => {
let json = serde_json::to_string(&result).unwrap();
Ok(HttpResponse::Ok().body(json))
@ -186,7 +195,7 @@ async fn clear_all_documents(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
match data.clear_documents(&path.index_uid).await {
match data.clear_documents(path.index_uid.clone()).await {
Ok(update) => {
let json = serde_json::to_string(&update).unwrap();
Ok(HttpResponse::Ok().body(json))