From d80e8b64afcca8a7cba6f7ce86c6758064fabdd4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 1 Jun 2022 15:30:39 +0200 Subject: [PATCH] Align the tasks route API to the new spec --- meilisearch-http/src/routes/tasks.rs | 30 +++++++++------------------- meilisearch-http/src/task.rs | 3 ++- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/meilisearch-http/src/routes/tasks.rs b/meilisearch-http/src/routes/tasks.rs index a82ca835f..49554858d 100644 --- a/meilisearch-http/src/routes/tasks.rs +++ b/meilisearch-http/src/routes/tasks.rs @@ -30,7 +30,7 @@ pub struct TaskFilterQuery { index_uid: Option>>, #[serde(default = "DEFAULT_LIMIT")] limit: usize, - after: Option, + from: Option, } #[rustfmt::skip] @@ -74,7 +74,7 @@ async fn get_tasks( status, index_uid, limit, - after, + from, } = params.into_inner(); let search_rules = &meilisearch.filters().search_rules; @@ -135,25 +135,11 @@ async fn get_tasks( indexes_filters }; - let offset = match after { - Some(0) => { - let tasks = TaskListView { - results: vec![], - limit, - after: None, - }; - return Ok(HttpResponse::Ok().json(tasks)); - } - // We -1 here because we need an offset and we must exclude the `after` one. - Some(n) => Some(n - 1), - None => None, - }; - // We +1 just to know if there is more after this "page" or not. let limit = limit.saturating_add(1); let mut tasks_results = meilisearch - .list_tasks(filters, Some(limit), offset) + .list_tasks(filters, Some(limit), from) .await? .into_iter() .map(TaskView::from) @@ -161,17 +147,19 @@ async fn get_tasks( // If we were able to fetch the number +1 tasks we asked // it means that there is more to come. - let after = if tasks_results.len() == limit { - tasks_results.pop(); - tasks_results.last().map(|t| t.uid) + let next = if tasks_results.len() == limit { + tasks_results.pop().map(|t| t.uid) } else { None }; + let from = tasks_results.first().map(|t| t.uid); + let tasks = TaskListView { results: tasks_results, limit: limit.saturating_sub(1), - after, + from, + next, }; Ok(HttpResponse::Ok().json(tasks)) diff --git a/meilisearch-http/src/task.rs b/meilisearch-http/src/task.rs index 8eec71a4e..f8ba941d8 100644 --- a/meilisearch-http/src/task.rs +++ b/meilisearch-http/src/task.rs @@ -371,7 +371,8 @@ impl From for TaskView { pub struct TaskListView { pub results: Vec, pub limit: usize, - pub after: Option, + pub from: Option, + pub next: Option, } #[derive(Debug, Serialize)]