mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
implement delete single document
This commit is contained in:
parent
c317af58bc
commit
28b9c158b1
4 changed files with 22 additions and 15 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue