2020-04-22 23:43:51 +08:00
|
|
|
use actix_web::{web, HttpResponse};
|
|
|
|
use actix_web_macros::{delete, get, post, put};
|
2019-11-20 00:39:30 +08:00
|
|
|
use chrono::{DateTime, Utc};
|
2019-11-21 00:28:46 +08:00
|
|
|
use log::error;
|
2019-11-19 23:07:24 +08:00
|
|
|
use rand::seq::SliceRandom;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2019-10-31 22:00:36 +08:00
|
|
|
|
2020-04-08 20:13:45 +08:00
|
|
|
use crate::error::ResponseError;
|
2020-04-22 23:43:51 +08:00
|
|
|
use crate::helpers::Authentication;
|
2020-04-09 17:11:48 +08:00
|
|
|
use crate::routes::IndexParam;
|
2020-04-11 01:05:05 +08:00
|
|
|
use crate::Data;
|
2019-10-31 22:00:36 +08:00
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
|
|
|
cfg.service(list_indexes)
|
|
|
|
.service(get_index)
|
|
|
|
.service(create_index)
|
|
|
|
.service(update_index)
|
|
|
|
.service(delete_index)
|
|
|
|
.service(get_update_status)
|
|
|
|
.service(get_all_updates_status);
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:07:24 +08:00
|
|
|
fn generate_uid() -> String {
|
|
|
|
let mut rng = rand::thread_rng();
|
2019-11-20 00:42:47 +08:00
|
|
|
let sample = b"abcdefghijklmnopqrstuvwxyz0123456789";
|
2019-11-19 23:07:24 +08:00
|
|
|
sample
|
|
|
|
.choose_multiple(&mut rng, 8)
|
|
|
|
.map(|c| *c as char)
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:13:45 +08:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-04-22 23:43:51 +08:00
|
|
|
struct IndexResponse {
|
2020-04-08 20:13:45 +08:00
|
|
|
name: String,
|
|
|
|
uid: String,
|
|
|
|
created_at: DateTime<Utc>,
|
|
|
|
updated_at: DateTime<Utc>,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
}
|
2019-11-20 18:24:08 +08:00
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
#[get("/indexes", wrap = "Authentication::Private")]
|
|
|
|
async fn list_indexes(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
|
2020-04-17 20:52:13 +08:00
|
|
|
let reader = data.db.main_read_txn()?;
|
2019-11-20 16:57:27 +08:00
|
|
|
|
2020-04-16 17:09:47 +08:00
|
|
|
let mut response = Vec::new();
|
2019-11-20 16:57:27 +08:00
|
|
|
|
2020-04-08 20:13:45 +08:00
|
|
|
for index_uid in data.db.indexes_uids() {
|
|
|
|
let index = data.db.open_index(&index_uid);
|
2019-11-21 00:28:46 +08:00
|
|
|
|
|
|
|
match index {
|
|
|
|
Some(index) => {
|
2020-04-17 20:52:13 +08:00
|
|
|
let name = index.main.name(&reader)?.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the name of an index",
|
|
|
|
))?;
|
2020-04-11 01:05:05 +08:00
|
|
|
let created_at = index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.created_at(&reader)?
|
|
|
|
.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the create date of an index",
|
2020-04-11 01:05:05 +08:00
|
|
|
))?;
|
|
|
|
let updated_at = index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.updated_at(&reader)?
|
|
|
|
.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the last update date of an index",
|
2020-04-11 01:05:05 +08:00
|
|
|
))?;
|
2019-11-21 00:28:46 +08:00
|
|
|
|
2020-03-10 01:40:49 +08:00
|
|
|
let primary_key = match index.main.schema(&reader) {
|
|
|
|
Ok(Some(schema)) => match schema.primary_key() {
|
|
|
|
Some(primary_key) => Some(primary_key.to_owned()),
|
2020-03-10 18:29:56 +08:00
|
|
|
None => None,
|
2020-03-06 01:29:10 +08:00
|
|
|
},
|
2020-02-27 01:49:17 +08:00
|
|
|
_ => None,
|
2020-02-13 00:00:14 +08:00
|
|
|
};
|
|
|
|
|
2019-12-19 17:32:17 +08:00
|
|
|
let index_response = IndexResponse {
|
2019-11-21 00:28:46 +08:00
|
|
|
name,
|
|
|
|
uid: index_uid,
|
|
|
|
created_at,
|
|
|
|
updated_at,
|
2020-03-10 01:40:49 +08:00
|
|
|
primary_key,
|
2019-11-21 00:28:46 +08:00
|
|
|
};
|
2020-04-16 17:09:47 +08:00
|
|
|
response.push(index_response);
|
2019-11-21 00:28:46 +08:00
|
|
|
}
|
|
|
|
None => error!(
|
|
|
|
"Index {} is referenced in the indexes list but cannot be found",
|
|
|
|
index_uid
|
|
|
|
),
|
|
|
|
}
|
2019-11-20 16:57:27 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 17:09:47 +08:00
|
|
|
Ok(HttpResponse::Ok().json(response))
|
2019-11-20 00:38:02 +08:00
|
|
|
}
|
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
#[get("/indexes/{index_uid}", wrap = "Authentication::Private")]
|
|
|
|
async fn get_index(
|
2020-04-08 20:13:45 +08:00
|
|
|
data: web::Data<Data>,
|
2020-04-09 17:11:48 +08:00
|
|
|
path: web::Path<IndexParam>,
|
2020-04-17 20:52:13 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-04-11 01:05:05 +08:00
|
|
|
let index = data
|
|
|
|
.db
|
2020-04-17 20:52:13 +08:00
|
|
|
.open_index(&path.index_uid)
|
|
|
|
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
|
2019-11-20 00:38:02 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let reader = data.db.main_read_txn()?;
|
2019-11-20 00:38:02 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let name = index.main.name(&reader)?.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the name of an index",
|
|
|
|
))?;
|
2020-04-11 01:05:05 +08:00
|
|
|
let created_at = index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.created_at(&reader)?
|
|
|
|
.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the create date of an index",
|
2020-04-11 01:05:05 +08:00
|
|
|
))?;
|
|
|
|
let updated_at = index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.updated_at(&reader)?
|
|
|
|
.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the last update date of an index",
|
2020-04-11 01:05:05 +08:00
|
|
|
))?;
|
2019-11-20 00:38:02 +08:00
|
|
|
|
2020-03-10 01:40:49 +08:00
|
|
|
let primary_key = match index.main.schema(&reader) {
|
|
|
|
Ok(Some(schema)) => match schema.primary_key() {
|
|
|
|
Some(primary_key) => Some(primary_key.to_owned()),
|
2020-03-10 18:29:56 +08:00
|
|
|
None => None,
|
2020-03-06 01:29:10 +08:00
|
|
|
},
|
2020-02-27 01:49:17 +08:00
|
|
|
_ => None,
|
2020-02-13 00:00:14 +08:00
|
|
|
};
|
|
|
|
|
2020-04-16 17:09:47 +08:00
|
|
|
Ok(HttpResponse::Ok().json(IndexResponse {
|
2019-11-20 00:38:02 +08:00
|
|
|
name,
|
2020-04-09 17:11:48 +08:00
|
|
|
uid: path.index_uid.clone(),
|
2019-11-20 00:38:02 +08:00
|
|
|
created_at,
|
|
|
|
updated_at,
|
2020-03-10 01:40:49 +08:00
|
|
|
primary_key,
|
2020-04-08 20:13:45 +08:00
|
|
|
}))
|
2019-11-20 00:38:02 +08:00
|
|
|
}
|
|
|
|
|
2019-11-21 00:28:46 +08:00
|
|
|
#[derive(Debug, Deserialize)]
|
2019-11-19 23:07:24 +08:00
|
|
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
2020-04-22 23:43:51 +08:00
|
|
|
struct IndexCreateRequest {
|
2020-01-16 00:11:10 +08:00
|
|
|
name: Option<String>,
|
2019-11-22 18:18:46 +08:00
|
|
|
uid: Option<String>,
|
2020-03-10 01:40:49 +08:00
|
|
|
primary_key: Option<String>,
|
2019-11-19 23:07:24 +08:00
|
|
|
}
|
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
#[post("/indexes", wrap = "Authentication::Private")]
|
|
|
|
async fn create_index(
|
2020-04-08 20:13:45 +08:00
|
|
|
data: web::Data<Data>,
|
2020-04-11 01:05:05 +08:00
|
|
|
body: web::Json<IndexCreateRequest>,
|
2020-04-17 20:52:13 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-01-16 00:11:10 +08:00
|
|
|
if let (None, None) = (body.name.clone(), body.uid.clone()) {
|
2020-04-17 20:52:13 +08:00
|
|
|
return Err(ResponseError::bad_request(
|
|
|
|
"Index creation must have an uid",
|
|
|
|
));
|
2020-01-16 00:11:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:00:52 +08:00
|
|
|
let uid = match &body.uid {
|
2020-03-05 18:44:30 +08:00
|
|
|
Some(uid) => {
|
2020-03-10 18:29:56 +08:00
|
|
|
if uid
|
|
|
|
.chars()
|
|
|
|
.all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_')
|
|
|
|
{
|
2020-04-24 21:00:52 +08:00
|
|
|
uid.to_owned()
|
2020-03-05 18:44:30 +08:00
|
|
|
} else {
|
2020-04-17 20:52:13 +08:00
|
|
|
return Err(ResponseError::InvalidIndexUid);
|
2020-03-05 18:44:30 +08:00
|
|
|
}
|
2020-03-10 18:29:56 +08:00
|
|
|
}
|
2019-11-22 18:18:46 +08:00
|
|
|
None => loop {
|
|
|
|
let uid = generate_uid();
|
2020-04-08 20:13:45 +08:00
|
|
|
if data.db.open_index(&uid).is_none() {
|
2019-11-22 18:18:46 +08:00
|
|
|
break uid;
|
|
|
|
}
|
|
|
|
},
|
2019-11-22 18:08:29 +08:00
|
|
|
};
|
|
|
|
|
2020-04-11 01:05:05 +08:00
|
|
|
let created_index = data
|
|
|
|
.db
|
|
|
|
.create_index(&uid)
|
2020-04-17 20:52:13 +08:00
|
|
|
.map_err(ResponseError::create_index)?;
|
2020-04-08 20:13:45 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let mut writer = data.db.main_write_txn()?;
|
2020-04-08 20:13:45 +08:00
|
|
|
|
2020-04-24 21:00:52 +08:00
|
|
|
let name = body.name.as_ref().unwrap_or(&uid);
|
|
|
|
created_index.main.put_name(&mut writer, name)?;
|
2019-10-31 22:00:36 +08:00
|
|
|
|
2020-01-23 18:30:18 +08:00
|
|
|
let created_at = created_index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.created_at(&writer)?
|
|
|
|
.ok_or(ResponseError::internal("Impossible to read created at"))?;
|
2020-04-08 20:13:45 +08:00
|
|
|
|
2020-01-23 18:30:18 +08:00
|
|
|
let updated_at = created_index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.updated_at(&writer)?
|
|
|
|
.ok_or(ResponseError::internal("Impossible to read updated at"))?;
|
2019-11-19 23:07:24 +08:00
|
|
|
|
2020-03-10 01:40:49 +08:00
|
|
|
if let Some(id) = body.primary_key.clone() {
|
2020-04-17 20:52:13 +08:00
|
|
|
if let Some(mut schema) = created_index.main.schema(&writer)? {
|
2020-04-11 01:05:05 +08:00
|
|
|
schema
|
|
|
|
.set_primary_key(&id)
|
2020-04-17 20:52:13 +08:00
|
|
|
.map_err(ResponseError::bad_request)?;
|
|
|
|
created_index.main.put_schema(&mut writer, &schema)?;
|
2020-03-06 01:29:10 +08:00
|
|
|
}
|
2020-01-29 00:45:29 +08:00
|
|
|
}
|
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
writer.commit()?;
|
2019-10-31 22:00:36 +08:00
|
|
|
|
2020-04-16 17:09:47 +08:00
|
|
|
Ok(HttpResponse::Created().json(IndexResponse {
|
2020-04-24 21:00:52 +08:00
|
|
|
name: name.to_string(),
|
2019-11-22 18:18:46 +08:00
|
|
|
uid,
|
2020-01-16 23:14:30 +08:00
|
|
|
created_at,
|
|
|
|
updated_at,
|
2020-04-08 20:13:45 +08:00
|
|
|
primary_key: body.primary_key.clone(),
|
|
|
|
}))
|
2019-10-31 22:00:36 +08:00
|
|
|
}
|
|
|
|
|
2019-11-21 00:28:46 +08:00
|
|
|
#[derive(Debug, Deserialize)]
|
2019-11-20 22:00:06 +08:00
|
|
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
2020-04-22 23:43:51 +08:00
|
|
|
struct UpdateIndexRequest {
|
2020-02-13 00:00:14 +08:00
|
|
|
name: Option<String>,
|
2020-03-10 01:40:49 +08:00
|
|
|
primary_key: Option<String>,
|
2019-11-20 22:00:06 +08:00
|
|
|
}
|
|
|
|
|
2019-11-21 00:28:46 +08:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-04-22 23:43:51 +08:00
|
|
|
struct UpdateIndexResponse {
|
2019-11-20 22:00:06 +08:00
|
|
|
name: String,
|
|
|
|
uid: String,
|
|
|
|
created_at: DateTime<Utc>,
|
|
|
|
updated_at: DateTime<Utc>,
|
2020-03-10 01:40:49 +08:00
|
|
|
primary_key: Option<String>,
|
2019-11-20 22:00:06 +08:00
|
|
|
}
|
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
#[put("/indexes/{index_uid}", wrap = "Authentication::Private")]
|
|
|
|
async fn update_index(
|
2020-04-08 20:13:45 +08:00
|
|
|
data: web::Data<Data>,
|
2020-04-09 17:11:48 +08:00
|
|
|
path: web::Path<IndexParam>,
|
2020-04-11 01:05:05 +08:00
|
|
|
body: web::Json<IndexCreateRequest>,
|
2020-04-17 20:52:13 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-04-11 01:05:05 +08:00
|
|
|
let index = data
|
|
|
|
.db
|
2020-04-17 20:52:13 +08:00
|
|
|
.open_index(&path.index_uid)
|
|
|
|
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
|
2019-11-20 22:00:06 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let mut writer = data.db.main_write_txn()?;
|
2020-01-16 23:58:57 +08:00
|
|
|
|
2020-04-24 21:00:52 +08:00
|
|
|
if let Some(name) = &body.name {
|
|
|
|
index.main.put_name(&mut writer, name)?;
|
2020-02-13 00:00:14 +08:00
|
|
|
}
|
2020-01-16 23:58:57 +08:00
|
|
|
|
2020-03-10 01:40:49 +08:00
|
|
|
if let Some(id) = body.primary_key.clone() {
|
2020-04-17 20:52:13 +08:00
|
|
|
if let Some(mut schema) = index.main.schema(&writer)? {
|
2020-03-10 01:40:49 +08:00
|
|
|
match schema.primary_key() {
|
2020-03-06 01:29:10 +08:00
|
|
|
Some(_) => {
|
2020-04-17 20:52:13 +08:00
|
|
|
return Err(ResponseError::bad_request(
|
|
|
|
"The primary key cannot be updated",
|
|
|
|
));
|
2020-03-10 18:29:56 +08:00
|
|
|
}
|
2020-03-06 01:29:10 +08:00
|
|
|
None => {
|
2020-04-17 20:52:13 +08:00
|
|
|
schema.set_primary_key(&id)?;
|
|
|
|
index.main.put_schema(&mut writer, &schema)?;
|
2020-03-06 01:29:10 +08:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 00:00:14 +08:00
|
|
|
}
|
|
|
|
}
|
2020-01-16 23:58:57 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
index.main.put_updated_at(&mut writer)?;
|
|
|
|
writer.commit()?;
|
2020-01-16 23:58:57 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let reader = data.db.main_read_txn()?;
|
2020-04-08 20:13:45 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let name = index.main.name(&reader)?.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the name of an index",
|
|
|
|
))?;
|
2020-04-11 01:05:05 +08:00
|
|
|
let created_at = index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.created_at(&reader)?
|
|
|
|
.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the create date of an index",
|
2020-04-11 01:05:05 +08:00
|
|
|
))?;
|
|
|
|
let updated_at = index
|
|
|
|
.main
|
2020-04-17 20:52:13 +08:00
|
|
|
.updated_at(&reader)?
|
|
|
|
.ok_or(ResponseError::internal(
|
|
|
|
"Impossible to get the last update date of an index",
|
2020-04-11 01:05:05 +08:00
|
|
|
))?;
|
2019-11-20 22:00:06 +08:00
|
|
|
|
2020-03-10 01:40:49 +08:00
|
|
|
let primary_key = match index.main.schema(&reader) {
|
2020-03-10 18:29:56 +08:00
|
|
|
Ok(Some(schema)) => match schema.primary_key() {
|
|
|
|
Some(primary_key) => Some(primary_key.to_owned()),
|
|
|
|
None => None,
|
2020-03-06 01:29:10 +08:00
|
|
|
},
|
2020-02-27 01:49:17 +08:00
|
|
|
_ => None,
|
2020-02-13 00:00:14 +08:00
|
|
|
};
|
|
|
|
|
2020-04-16 17:09:47 +08:00
|
|
|
Ok(HttpResponse::Ok().json(IndexResponse {
|
2020-02-13 00:00:14 +08:00
|
|
|
name,
|
2020-04-09 17:11:48 +08:00
|
|
|
uid: path.index_uid.clone(),
|
2019-11-20 22:00:06 +08:00
|
|
|
created_at,
|
|
|
|
updated_at,
|
2020-03-10 01:40:49 +08:00
|
|
|
primary_key,
|
2020-04-08 20:13:45 +08:00
|
|
|
}))
|
2019-11-20 22:00:06 +08:00
|
|
|
}
|
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
#[delete("/indexes/{index_uid}", wrap = "Authentication::Private")]
|
|
|
|
async fn delete_index(
|
2020-04-08 20:13:45 +08:00
|
|
|
data: web::Data<Data>,
|
2020-04-09 17:11:48 +08:00
|
|
|
path: web::Path<IndexParam>,
|
2020-04-17 20:52:13 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
|
|
|
data.db.delete_index(&path.index_uid)?;
|
2019-10-31 22:00:36 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
Ok(HttpResponse::NoContent().finish())
|
2019-10-31 22:00:36 +08:00
|
|
|
}
|
2020-04-09 16:39:34 +08:00
|
|
|
|
2020-04-24 21:00:52 +08:00
|
|
|
#[derive(Deserialize)]
|
2020-04-22 23:43:51 +08:00
|
|
|
struct UpdateParam {
|
2020-04-09 17:11:48 +08:00
|
|
|
index_uid: String,
|
2020-04-11 01:05:05 +08:00
|
|
|
update_id: u64,
|
2020-04-09 17:11:48 +08:00
|
|
|
}
|
2020-04-09 16:39:34 +08:00
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
#[get(
|
|
|
|
"/indexes/{index_uid}/updates/{update_id}",
|
|
|
|
wrap = "Authentication::Private"
|
|
|
|
)]
|
|
|
|
async fn get_update_status(
|
2020-04-09 16:39:34 +08:00
|
|
|
data: web::Data<Data>,
|
2020-04-09 17:11:48 +08:00
|
|
|
path: web::Path<UpdateParam>,
|
2020-04-17 20:52:13 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-04-11 01:05:05 +08:00
|
|
|
let index = data
|
|
|
|
.db
|
2020-04-17 20:52:13 +08:00
|
|
|
.open_index(&path.index_uid)
|
|
|
|
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
|
2020-04-09 16:39:34 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let reader = data.db.update_read_txn()?;
|
2020-04-09 16:39:34 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let status = index.update_status(&reader, path.update_id)?;
|
2020-04-09 16:39:34 +08:00
|
|
|
|
|
|
|
match status {
|
2020-04-16 17:09:47 +08:00
|
|
|
Some(status) => Ok(HttpResponse::Ok().json(status)),
|
2020-04-17 20:52:13 +08:00
|
|
|
None => Err(ResponseError::NotFound(format!(
|
|
|
|
"Update {} not found",
|
|
|
|
path.update_id
|
|
|
|
))),
|
2020-04-09 16:39:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 23:43:51 +08:00
|
|
|
#[get("/indexes/{index_uid}/updates", wrap = "Authentication::Private")]
|
|
|
|
async fn get_all_updates_status(
|
2020-04-09 16:39:34 +08:00
|
|
|
data: web::Data<Data>,
|
2020-04-09 17:11:48 +08:00
|
|
|
path: web::Path<IndexParam>,
|
2020-04-17 20:52:13 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-04-11 01:05:05 +08:00
|
|
|
let index = data
|
|
|
|
.db
|
2020-04-17 20:52:13 +08:00
|
|
|
.open_index(&path.index_uid)
|
|
|
|
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
|
2020-04-09 16:39:34 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let reader = data.db.update_read_txn()?;
|
2020-04-09 16:39:34 +08:00
|
|
|
|
2020-04-17 20:52:13 +08:00
|
|
|
let response = index.all_updates_status(&reader)?;
|
2020-04-09 16:39:34 +08:00
|
|
|
|
2020-04-16 17:09:47 +08:00
|
|
|
Ok(HttpResponse::Ok().json(response))
|
2020-04-09 16:39:34 +08:00
|
|
|
}
|