Browse Source

Capture the cases names

The idea is to, later, retrieve each case on separate tasks, 'cause
getting all of them in a single request is sloooooooooooow.
master
Julio Biason 2 years ago
parent
commit
e3b91e5c2f
  1. 22
      axumtest/src/cases/mod.rs

22
axumtest/src/cases/mod.rs

@ -7,7 +7,10 @@ use axum::middleware;
use axum::routing::get;
use axum::Router;
use futures::stream::TryStreamExt;
use futures::StreamExt;
use mongodb::bson::doc;
use mongodb::bson::Document;
use mongodb::options::FindOptions;
use crate::auth;
use crate::State;
@ -32,9 +35,20 @@ pub fn router(state: Arc<State>, ci_usr: String, ci_pwd: String, ci_role: String
async fn all_cases_on_collection(Path(collection): Path<String>, state: Arc<State>) -> String {
let collection = state.db.collection::<Document>(&collection);
let mut cursor = collection.find(None, None).await.unwrap();
while let Some(record) = cursor.try_next().await.unwrap() {
tracing::debug!("{:?}", record.get_str("caseID"));
}
let options = FindOptions::builder()
.projection(doc! { "caseID": 1 })
.build();
let cursor = collection.find(None, options).await.unwrap();
let result = cursor
.map(|r| r.unwrap().get_str("caseID").unwrap().to_lowercase())
.collect::<Vec<String>>()
.await;
// while let Some(record) = cursor.try_next().await.unwrap() {
// tracing::debug!("{:?}", record.get_str("caseID").unwrap());
// }
tracing::debug!("Cases: {:?}", result);
format!("Cases!")
}

Loading…
Cancel
Save