From 08b5123380b990a40b28ffe5440084b03169f1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 26 Oct 2022 13:09:42 +0200 Subject: [PATCH] Display more than one indexUid in a task view if necessary --- meilisearch-http/src/routes/tasks.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/src/routes/tasks.rs b/meilisearch-http/src/routes/tasks.rs index 41a499c20..544270627 100644 --- a/meilisearch-http/src/routes/tasks.rs +++ b/meilisearch-http/src/routes/tasks.rs @@ -32,12 +32,30 @@ pub fn configure(cfg: &mut web::ServiceConfig) { .service(web::resource("/{task_id}").route(web::get().to(SeqHandler(get_task)))); } +#[derive(Default, Debug, Clone, PartialEq, Serialize)] +#[serde(untagged, rename_all = "camelCase")] +pub enum IndexUidView { + Multiple(Vec), + Single(String), + #[default] + None, +} +impl IndexUidView { + fn new(indexes: &[&str]) -> Self { + match indexes { + [] => Self::None, + [index] => Self::Single(index.to_string()), + indexes => Self::Multiple(indexes.iter().map(ToString::to_string).collect()), + } + } +} + #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct TaskView { pub uid: TaskId, #[serde(default)] - pub index_uid: Option, + pub index_uid: IndexUidView, pub status: Status, #[serde(rename = "type")] pub kind: Kind, @@ -64,7 +82,7 @@ impl TaskView { pub fn from_task(task: &Task) -> TaskView { TaskView { uid: task.uid, - index_uid: task.index_uid().map(ToOwned::to_owned), + index_uid: IndexUidView::new(&task.indexes()), status: task.status, kind: task.kind.as_kind(), canceled_by: task.canceled_by,