2020-12-12 13:32:06 +01:00
|
|
|
use actix_web::{delete, get, post, put};
|
|
|
|
use actix_web::{web, HttpResponse};
|
|
|
|
use chrono::{DateTime, Utc};
|
2021-01-28 17:20:51 +01:00
|
|
|
use log::error;
|
2020-12-12 13:32:06 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use crate::Data;
|
2020-12-22 14:02:41 +01:00
|
|
|
use crate::error::ResponseError;
|
2020-12-12 13:32:06 +01:00
|
|
|
use crate::helpers::Authentication;
|
|
|
|
use crate::routes::IndexParam;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/indexes", wrap = "Authentication::Private")]
|
2021-02-03 17:44:20 +01:00
|
|
|
async fn list_indexes(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
|
|
|
|
match data.list_indexes() {
|
|
|
|
Ok(indexes) => {
|
|
|
|
let json = serde_json::to_string(&indexes).unwrap();
|
|
|
|
Ok(HttpResponse::Ok().body(&json))
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
error!("error listing indexes: {}", e);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/indexes/{index_uid}", wrap = "Authentication::Private")]
|
|
|
|
async fn get_index(
|
2020-12-22 14:02:41 +01:00
|
|
|
_data: web::Data<Data>,
|
|
|
|
_path: web::Path<IndexParam>,
|
2020-12-12 13:32:06 +01:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-12-12 16:04:37 +01:00
|
|
|
todo!()
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
|
|
struct IndexCreateRequest {
|
|
|
|
name: Option<String>,
|
|
|
|
uid: Option<String>,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/indexes", wrap = "Authentication::Private")]
|
|
|
|
async fn create_index(
|
2020-12-22 14:02:41 +01:00
|
|
|
_data: web::Data<Data>,
|
|
|
|
_body: web::Json<IndexCreateRequest>,
|
2020-12-12 13:32:06 +01:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-12-12 16:04:37 +01:00
|
|
|
todo!()
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
|
|
struct UpdateIndexRequest {
|
|
|
|
name: Option<String>,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct UpdateIndexResponse {
|
|
|
|
name: String,
|
|
|
|
uid: String,
|
|
|
|
created_at: DateTime<Utc>,
|
|
|
|
updated_at: DateTime<Utc>,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[put("/indexes/{index_uid}", wrap = "Authentication::Private")]
|
|
|
|
async fn update_index(
|
2020-12-22 14:02:41 +01:00
|
|
|
_data: web::Data<Data>,
|
|
|
|
_path: web::Path<IndexParam>,
|
|
|
|
_body: web::Json<IndexCreateRequest>,
|
2020-12-12 13:32:06 +01:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-12-12 16:04:37 +01:00
|
|
|
todo!()
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[delete("/indexes/{index_uid}", wrap = "Authentication::Private")]
|
|
|
|
async fn delete_index(
|
2020-12-22 14:02:41 +01:00
|
|
|
_data: web::Data<Data>,
|
|
|
|
_path: web::Path<IndexParam>,
|
2020-12-12 13:32:06 +01:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2020-12-12 16:04:37 +01:00
|
|
|
todo!()
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct UpdateParam {
|
2021-01-28 17:20:51 +01:00
|
|
|
index_uid: String,
|
|
|
|
update_id: u64,
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get(
|
|
|
|
"/indexes/{index_uid}/updates/{update_id}",
|
|
|
|
wrap = "Authentication::Private"
|
|
|
|
)]
|
|
|
|
async fn get_update_status(
|
2021-01-28 17:20:51 +01:00
|
|
|
data: web::Data<Data>,
|
|
|
|
path: web::Path<UpdateParam>,
|
2020-12-12 13:32:06 +01:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2021-01-28 17:20:51 +01:00
|
|
|
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!()
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/indexes/{index_uid}/updates", wrap = "Authentication::Private")]
|
|
|
|
async fn get_all_updates_status(
|
2021-01-28 18:32:24 +01:00
|
|
|
data: web::Data<Data>,
|
|
|
|
path: web::Path<IndexParam>,
|
2020-12-12 13:32:06 +01:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2021-01-28 18:32:24 +01:00
|
|
|
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!()
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|