mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-11 15:38:55 +01:00
fix delete-batch route; #493
This commit is contained in:
parent
81ce90e57f
commit
54c675e195
@ -65,7 +65,7 @@ pub fn load_routes(app: &mut tide::Server<Data>) {
|
|||||||
.get(|ctx| into_response(document::get_document(ctx)))
|
.get(|ctx| into_response(document::get_document(ctx)))
|
||||||
.delete(|ctx| into_response(document::delete_document(ctx)));
|
.delete(|ctx| into_response(document::delete_document(ctx)));
|
||||||
|
|
||||||
app.at("/indexes/:index/documents/:identifier/delete-batch")
|
app.at("/indexes/:index/documents/delete-batch")
|
||||||
.post(|ctx| into_response(document::delete_multiple_documents(ctx)));
|
.post(|ctx| into_response(document::delete_multiple_documents(ctx)));
|
||||||
|
|
||||||
app.at("/indexes/:index/settings")
|
app.at("/indexes/:index/settings")
|
||||||
|
@ -58,6 +58,7 @@ impl Server {
|
|||||||
let response: Value = serde_json::from_slice(&buf).unwrap();
|
let response: Value = serde_json::from_slice(&buf).unwrap();
|
||||||
|
|
||||||
if response["status"] == "processed" {
|
if response["status"] == "processed" {
|
||||||
|
eprintln!("{:?}", response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
block_on(sleep(Duration::from_secs(1)));
|
block_on(sleep(Duration::from_secs(1)));
|
||||||
@ -219,14 +220,14 @@ impl Server {
|
|||||||
self.delete_request_async(&url);
|
self.delete_request_async(&url);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_document(&mut self, document_id: u64) -> (Value, StatusCode) {
|
pub fn get_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
|
||||||
let url = format!("/indexes/{}/documents/{}", self.uid, document_id);
|
let url = format!("/indexes/{}/documents/{}", self.uid, document_id.to_string());
|
||||||
self.get_request(&url)
|
self.get_request(&url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_document(&mut self, document_id: u64) -> (Value, StatusCode) {
|
pub fn delete_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
|
||||||
let url = format!("/indexes/{}/documents/{}", self.uid, document_id);
|
let url = format!("/indexes/{}/documents/{}", self.uid, document_id.to_string());
|
||||||
self.delete_request(&url)
|
self.delete_request_async(&url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_multiple_documents(&mut self, body: Value) {
|
pub fn delete_multiple_documents(&mut self, body: Value) {
|
||||||
|
30
meilisearch-http/tests/documents_delete.rs
Normal file
30
meilisearch-http/tests/documents_delete.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
mod common;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete() {
|
||||||
|
let mut server = common::Server::with_uid("movies");
|
||||||
|
server.populate_movies();
|
||||||
|
|
||||||
|
let (_response, status_code) = server.get_document(419704);
|
||||||
|
assert_eq!(status_code, 200);
|
||||||
|
|
||||||
|
server.delete_document(419704);
|
||||||
|
|
||||||
|
let (_response, status_code) = server.get_document(419704);
|
||||||
|
assert_eq!(status_code, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_batch() {
|
||||||
|
let mut server = common::Server::with_uid("movies");
|
||||||
|
server.populate_movies();
|
||||||
|
|
||||||
|
let (_response, status_code) = server.get_document(419704);
|
||||||
|
assert_eq!(status_code, 200);
|
||||||
|
|
||||||
|
let body = serde_json::json!([419704,512200,181812]);
|
||||||
|
server.delete_multiple_documents(body);
|
||||||
|
|
||||||
|
let (_response, status_code) = server.get_document(419704);
|
||||||
|
assert_eq!(status_code, 404);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user