implement delete documents

This commit is contained in:
mpostma 2021-03-04 15:59:18 +01:00
parent 181eaf95f5
commit ae5581d37c
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
3 changed files with 31 additions and 24 deletions

View file

@ -229,21 +229,20 @@ async fn delete_documents(
path: web::Path<IndexParam>,
body: web::Json<Vec<Value>>,
) -> Result<HttpResponse, ResponseError> {
todo!()
//let ids = body
//.iter()
//.map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string()))
//.collect();
let ids = body
.iter()
.map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string()))
.collect();
//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))
//}
//Err(e) => {
//Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
//}
//}
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))
}
Err(e) => {
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
}
}
#[delete("/indexes/{index_uid}/documents", wrap = "Authentication::Private")]