WIP: refactor IndexController

change the architecture of the index controller to allow it to own an
index store.
This commit is contained in:
mpostma
2021-01-16 15:09:48 +01:00
parent 686f987180
commit 6a3f625e11
15 changed files with 1197 additions and 287 deletions

View File

@ -122,7 +122,7 @@ async fn add_documents_json(
) -> Result<HttpResponse, ResponseError> {
let addition_result = data
.add_documents(
&path.index_uid,
path.into_inner().index_uid,
IndexDocumentsMethod::UpdateDocuments,
UpdateFormat::Json,
body

View File

@ -1,7 +1,7 @@
use actix_web::{delete, get, post, put};
use actix_web::{web, HttpResponse};
use chrono::{DateTime, Utc};
use log::error;
//use log::error;
use serde::{Deserialize, Serialize};
use crate::Data;
@ -94,8 +94,8 @@ async fn delete_index(
#[derive(Deserialize)]
struct UpdateParam {
index_uid: String,
update_id: u64,
_index_uid: String,
_update_id: u64,
}
#[get(
@ -103,39 +103,41 @@ struct UpdateParam {
wrap = "Authentication::Private"
)]
async fn get_update_status(
data: web::Data<Data>,
path: web::Path<UpdateParam>,
_data: web::Data<Data>,
_path: web::Path<UpdateParam>,
) -> Result<HttpResponse, ResponseError> {
let result = data.get_update_status(&path.index_uid, path.update_id);
match result {
Ok(Some(meta)) => {
let json = serde_json::to_string(&meta).unwrap();
Ok(HttpResponse::Ok().body(json))
}
Ok(None) => {
todo!()
}
Err(e) => {
error!("{}", e);
todo!()
}
}
todo!()
//let result = data.get_update_status(&path.index_uid, path.update_id);
//match result {
//Ok(Some(meta)) => {
//let json = serde_json::to_string(&meta).unwrap();
//Ok(HttpResponse::Ok().body(json))
//}
//Ok(None) => {
//todo!()
//}
//Err(e) => {
//error!("{}", e);
//todo!()
//}
//}
}
#[get("/indexes/{index_uid}/updates", wrap = "Authentication::Private")]
async fn get_all_updates_status(
data: web::Data<Data>,
path: web::Path<IndexParam>,
_data: web::Data<Data>,
_path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
let result = data.get_updates_status(&path.index_uid);
match result {
Ok(metas) => {
let json = serde_json::to_string(&metas).unwrap();
Ok(HttpResponse::Ok().body(json))
}
Err(e) => {
error!("{}", e);
todo!()
}
}
todo!()
//let result = data.get_updates_status(&path.index_uid);
//match result {
//Ok(metas) => {
//let json = serde_json::to_string(&metas).unwrap();
//Ok(HttpResponse::Ok().body(json))
//}
//Err(e) => {
//error!("{}", e);
//todo!()
//}
//}
}

View File

@ -3,7 +3,7 @@ use log::error;
use crate::Data;
use crate::error::ResponseError;
use crate::updates::Settings;
use crate::index_controller::Settings;
use crate::helpers::Authentication;
#[macro_export]
@ -15,19 +15,19 @@ macro_rules! make_setting_route {
use crate::data;
use crate::error::ResponseError;
use crate::helpers::Authentication;
use crate::updates::Settings;
use crate::index_controller::Settings;
#[actix_web::delete($route, wrap = "Authentication::Private")]
pub async fn delete(
data: web::Data<data::Data>,
index_uid: web::Path<String>,
) -> Result<HttpResponse, ResponseError> {
use crate::updates::Settings;
use crate::index_controller::Settings;
let settings = Settings {
$attr: Some(None),
..Default::default()
};
match data.update_settings(index_uid.as_ref(), settings).await {
match data.update_settings(index_uid.into_inner(), settings).await {
Ok(update_status) => {
let json = serde_json::to_string(&update_status).unwrap();
Ok(HttpResponse::Ok().body(json))
@ -50,7 +50,7 @@ macro_rules! make_setting_route {
..Default::default()
};
match data.update_settings(index_uid.as_ref(), settings).await {
match data.update_settings(index_uid.into_inner(), settings).await {
Ok(update_status) => {
let json = serde_json::to_string(&update_status).unwrap();
Ok(HttpResponse::Ok().body(json))
@ -141,7 +141,7 @@ async fn update_all(
index_uid: web::Path<String>,
body: web::Json<Settings>,
) -> Result<HttpResponse, ResponseError> {
match data.update_settings(index_uid.as_ref(), body.into_inner()).await {
match data.update_settings(index_uid.into_inner(), body.into_inner()).await {
Ok(update_result) => {
let json = serde_json::to_string(&update_result).unwrap();
Ok(HttpResponse::Ok().body(json))
@ -176,7 +176,7 @@ async fn delete_all(
index_uid: web::Path<String>,
) -> Result<HttpResponse, ResponseError> {
let settings = Settings::cleared();
match data.update_settings(index_uid.as_ref(), settings).await {
match data.update_settings(index_uid.into_inner(), settings).await {
Ok(update_result) => {
let json = serde_json::to_string(&update_result).unwrap();
Ok(HttpResponse::Ok().body(json))