2020-12-12 13:32:06 +01:00
|
|
|
use std::collections::{HashMap, BTreeMap};
|
|
|
|
|
|
|
|
use actix_web::web;
|
|
|
|
use actix_web::HttpResponse;
|
|
|
|
use actix_web::get;
|
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use serde::Serialize;
|
|
|
|
|
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;
|
|
|
|
use crate::Data;
|
|
|
|
|
|
|
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
|
|
|
cfg.service(index_stats)
|
|
|
|
.service(get_stats)
|
|
|
|
.service(get_version);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct IndexStatsResponse {
|
|
|
|
number_of_documents: u64,
|
|
|
|
is_indexing: bool,
|
|
|
|
fields_distribution: BTreeMap<String, usize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/indexes/{index_uid}/stats", wrap = "Authentication::Private")]
|
|
|
|
async fn index_stats(
|
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(Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct StatsResult {
|
|
|
|
database_size: u64,
|
|
|
|
last_update: Option<DateTime<Utc>>,
|
|
|
|
indexes: HashMap<String, IndexStatsResponse>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/stats", wrap = "Authentication::Private")]
|
2020-12-22 14:02:41 +01:00
|
|
|
async fn get_stats(_data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
|
2020-12-12 16:04:37 +01:00
|
|
|
todo!()
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct VersionResponse {
|
|
|
|
commit_sha: String,
|
|
|
|
build_date: String,
|
|
|
|
pkg_version: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/version", wrap = "Authentication::Private")]
|
|
|
|
async fn get_version() -> HttpResponse {
|
2020-12-12 16:04:37 +01:00
|
|
|
todo!()
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|