mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 09:04:59 +08:00
Display more than one indexUid in a task view if necessary
This commit is contained in:
parent
1f75caae88
commit
08b5123380
@ -32,12 +32,30 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
.service(web::resource("/{task_id}").route(web::get().to(SeqHandler(get_task))));
|
.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<String>),
|
||||||
|
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)]
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct TaskView {
|
pub struct TaskView {
|
||||||
pub uid: TaskId,
|
pub uid: TaskId,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub index_uid: Option<String>,
|
pub index_uid: IndexUidView,
|
||||||
pub status: Status,
|
pub status: Status,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub kind: Kind,
|
pub kind: Kind,
|
||||||
@ -64,7 +82,7 @@ impl TaskView {
|
|||||||
pub fn from_task(task: &Task) -> TaskView {
|
pub fn from_task(task: &Task) -> TaskView {
|
||||||
TaskView {
|
TaskView {
|
||||||
uid: task.uid,
|
uid: task.uid,
|
||||||
index_uid: task.index_uid().map(ToOwned::to_owned),
|
index_uid: IndexUidView::new(&task.indexes()),
|
||||||
status: task.status,
|
status: task.status,
|
||||||
kind: task.kind.as_kind(),
|
kind: task.kind.as_kind(),
|
||||||
canceled_by: task.canceled_by,
|
canceled_by: task.canceled_by,
|
||||||
|
Loading…
Reference in New Issue
Block a user