From 394976d3302f22937c16dd13450b3139100e920c Mon Sep 17 00:00:00 2001 From: Quentin de Quelen Date: Wed, 20 Nov 2019 09:57:27 +0100 Subject: [PATCH] Update list_index route to return all index information, not only list of uid --- meilidb-http/src/routes/index.rs | 41 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/meilidb-http/src/routes/index.rs b/meilidb-http/src/routes/index.rs index e44bdf7cc..552f8d867 100644 --- a/meilidb-http/src/routes/index.rs +++ b/meilidb-http/src/routes/index.rs @@ -8,7 +8,6 @@ use serde_json::json; use tide::querystring::ContextExt as QSContextExt; use tide::response::IntoResponse; use tide::{Context, Response}; -use chrono::{DateTime, Utc}; use crate::error::{ResponseError, SResult}; use crate::helpers::tide::ContextExt; @@ -28,17 +27,49 @@ fn generate_uid() -> String { pub async fn list_indexes(ctx: Context) -> SResult { ctx.is_allowed(IndexesRead)?; - let list = ctx + + let indexes_uids = ctx .state() .db .indexes_uids() .map_err(ResponseError::internal)?; - Ok(tide::response::json(list)) + + let env = &ctx.state().db.env; + let mut reader = env.read_txn().map_err(ResponseError::internal)?; + + let mut response_body = Vec::new(); + + for index_uid in indexes_uids { + let index = ctx + .state() + .db + .open_index(&index_uid) + .ok_or(ResponseError::internal(&index_uid))?; + let name = index.main.name(&mut reader) + .map_err(ResponseError::internal)? + .ok_or(ResponseError::internal("Name not found"))?; + let created_at = index.main.created_at(&mut reader) + .map_err(ResponseError::internal)? + .ok_or(ResponseError::internal("Created date not found"))?; + let updated_at = index.main.updated_at(&mut reader) + .map_err(ResponseError::internal)? + .ok_or(ResponseError::internal("Updated date not found"))?; + + let index_reponse = IndexResponse { + name, + uid: index_uid, + created_at, + updated_at, + }; + response_body.push(index_reponse); + } + + Ok(tide::response::json(response_body)) } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] -struct GetIndexResponse { +struct IndexResponse { name: String, uid: String, created_at: DateTime, @@ -64,7 +95,7 @@ pub async fn get_index(ctx: Context) -> SResult { .map_err(ResponseError::internal)? .ok_or(ResponseError::internal("Updated date not found"))?; - let response_body = GetIndexResponse { + let response_body = IndexResponse { name, uid, created_at,