receive update

This commit is contained in:
mpostma 2021-02-26 17:14:11 +01:00
parent 672a4b5400
commit 6bcc302950
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
8 changed files with 181 additions and 459 deletions

View file

@ -3,7 +3,7 @@ use actix_web::{delete, get, post, put};
use actix_web::{web, HttpResponse};
use indexmap::IndexMap;
use log::error;
//use milli::update::{IndexDocumentsMethod, UpdateFormat};
use milli::update::{IndexDocumentsMethod, UpdateFormat};
use serde::Deserialize;
use serde_json::Value;
@ -142,26 +142,25 @@ async fn add_documents_json(
params: web::Query<UpdateDocumentsQuery>,
body: Payload,
) -> Result<HttpResponse, ResponseError> {
todo!()
//let addition_result = data
//.add_documents(
//path.into_inner().index_uid,
//IndexDocumentsMethod::ReplaceDocuments,
//UpdateFormat::Json,
//body,
//params.primary_key.clone(),
//).await;
let addition_result = data
.add_documents(
path.into_inner().index_uid,
IndexDocumentsMethod::ReplaceDocuments,
UpdateFormat::Json,
body,
params.primary_key.clone(),
).await;
//match addition_result {
//Ok(update) => {
//let value = serde_json::to_string(&update).unwrap();
//let response = HttpResponse::Ok().body(value);
//Ok(response)
//}
//Err(e) => {
//Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
//}
//}
match addition_result {
Ok(update) => {
let value = serde_json::to_string(&update).unwrap();
let response = HttpResponse::Ok().body(value);
Ok(response)
}
Err(e) => {
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
}
}