meilisearch/meilisearch-http/src/routes/dump.rs

43 lines
1014 B
Rust
Raw Normal View History

2021-05-05 20:11:56 +08:00
use actix_web::{post, get, web};
use actix_web::HttpResponse;
use serde::{Serialize, Deserialize};
2020-12-12 20:32:06 +08:00
2021-05-05 20:11:56 +08:00
use crate::error::ResponseError;
2020-12-12 20:32:06 +08:00
use crate::helpers::Authentication;
2021-05-05 20:11:56 +08:00
use crate::Data;
2020-12-12 20:32:06 +08:00
pub fn services(cfg: &mut web::ServiceConfig) {
2021-05-11 02:25:09 +08:00
cfg.service(create_dump)
2020-12-12 20:32:06 +08:00
.service(get_dump_status);
}
#[post("/dumps", wrap = "Authentication::Private")]
2021-05-11 02:25:09 +08:00
async fn create_dump(
2020-12-12 20:32:06 +08:00
data: web::Data<Data>,
) -> Result<HttpResponse, ResponseError> {
2021-05-11 02:25:09 +08:00
let res = data.create_dump().await?;
2021-05-05 20:11:56 +08:00
Ok(HttpResponse::Accepted().json(res))
2020-12-12 20:32:06 +08:00
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct DumpStatusResponse {
status: String,
}
#[derive(Deserialize)]
struct DumpParam {
2021-05-11 02:25:09 +08:00
dump_uid: String,
2020-12-12 20:32:06 +08:00
}
#[get("/dumps/{dump_uid}/status", wrap = "Authentication::Private")]
async fn get_dump_status(
2021-05-11 02:25:09 +08:00
data: web::Data<Data>,
path: web::Path<DumpParam>,
2020-12-12 20:32:06 +08:00
) -> Result<HttpResponse, ResponseError> {
2021-05-11 02:25:09 +08:00
let res = data.dump_status(path.dump_uid.clone()).await?;
Ok(HttpResponse::Ok().json(res))
2020-12-12 20:32:06 +08:00
}