diff --git a/src/data/updates.rs b/src/data/updates.rs index 6bb9b20f2..bb96c53c6 100644 --- a/src/data/updates.rs +++ b/src/data/updates.rs @@ -50,4 +50,20 @@ impl Data { pub fn get_update_status(&self, _index: &str, uid: u64) -> anyhow::Result>> { self.update_queue.get_update_status(uid) } + + pub fn get_updates_status(&self, _index: &str) -> anyhow::Result>> { + let result = self.update_queue.iter_metas(|processing, processed, pending, aborted, failed| { + let mut metas = processing + .map(UpdateStatus::from) + .into_iter() + .chain(processed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + .chain(pending.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + .chain(aborted.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + .chain(failed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + .collect::>(); + metas.sort_by(|a, b| a.id().cmp(&b.id())); + Ok(metas) + })?; + Ok(result) + } } diff --git a/src/routes/index.rs b/src/routes/index.rs index eb961a8dd..515e771e1 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -124,8 +124,18 @@ async fn get_update_status( #[get("/indexes/{index_uid}/updates", wrap = "Authentication::Private")] async fn get_all_updates_status( - _data: web::Data, - _path: web::Path, + data: web::Data, + path: web::Path, ) -> Result { - todo!() + let result = data.get_updates_status(&path.index_uid); + match result { + Ok(metas) => { + let json = serde_json::to_string(&metas).unwrap(); + Ok(HttpResponse::Ok().body(json)) + } + Err(e) => { + error!("{}", e); + todo!() + } + } }