Browse Source

Trying to deserialize the records

master
Julio Biason 2 years ago
parent
commit
6387d5a7f4
  1. 49
      axumtest/src/cases/mod.rs
  2. 33
      axumtest/src/entities/mod.rs

49
axumtest/src/cases/mod.rs

@ -7,13 +7,12 @@ 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 tokio::task::JoinHandle;
use crate::auth;
use crate::entities::Case;
use crate::State;
/// Build the routes for the cases resource.
@ -35,28 +34,34 @@ 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 = Arc::new(state.db.collection::<Document>(&collection));
let options = FindOptions::builder()
.projection(doc! { "caseID": 1 })
.build();
let mut cursor = collection.find(None, options).await.unwrap();
let mut calls = Vec::new();
let collection = state.db.collection::<Case>(&collection);
let mut cursor = collection.find(None, None).await.unwrap();
// let options = FindOptions::builder()
// .projection(doc! { "caseID": 1 })
// .build();
// let mut cursor = collection.find(None, options).await.unwrap();
// let mut calls = Vec::new();
while let Some(record) = cursor.try_next().await.unwrap() {
let name = record.get_str("caseID").unwrap();
let filter = doc! { "caseID": name };
let task_collection = Arc::clone(&collection);
let task = tokio::task::spawn(async move {
let record = task_collection.find_one(filter, None).await.unwrap();
record
});
calls.push(task);
}
// while let Some(record) = cursor.try_next().await.unwrap() {
// let name = record.get_str("caseID").unwrap();
// let filter = doc! { "caseID": name };
// tracing::debug!(name, "filter: {}", filter);
// let task_collection = Arc::clone(&collection);
// let task = tokio::task::spawn(async move {
// let record = task_collection.find_one(filter, None).await.unwrap();
// record
// });
for handle in calls {
let record = handle.await;
tracing::debug!("Case: {:?}", record);
// calls.push(task);
// }
// tracing::debug!("Awaiting data...");
// for handle in calls {
// let record = handle.await;
// tracing::debug!("Case: {:?}", record.unwrap());
// }
while let Some(record) = cursor.try_next().await.unwrap() {
tracing::debug!(?record);
}
format!("Cases!")

33
axumtest/src/entities/mod.rs

@ -1,5 +1,7 @@
//! Entities used in the system.
use std::collections::HashMap;
use clap::Parser;
use mongodb::Database;
@ -46,3 +48,34 @@ impl ErrorResponse {
}
}
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Comparison {
absolute_tolerance: f64,
relative_tolerance: f64,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Compare {
file_to_test: String,
entries_to_compare: HashMap<String, Comparison>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Case {
#[serde(default)]
files: Vec<String>,
timeout: Option<u16>,
#[serde(default)]
run: Vec<String>,
#[serde(default)]
parallel: Vec<String>,
procs: Option<u16>,
#[serde(default)]
tags: Vec<String>,
version: Option<u16>,
#[serde(default)]
compare: HashMap<String, Compare>,
}

Loading…
Cancel
Save