Browse Source

Show results

master
Julio Biason 2 years ago
parent
commit
5ee35f16d8
  1. 19
      axumtest/Cargo.lock
  2. 1
      axumtest/Cargo.toml
  3. 40
      axumtest/src/cases/mod.rs
  4. 7
      axumtest/src/main.rs

19
axumtest/Cargo.lock generated

@ -112,6 +112,7 @@ dependencies = [
"axum", "axum",
"clap", "clap",
"dotenv", "dotenv",
"futures",
"mongodb", "mongodb",
"serde", "serde",
"serde_json", "serde_json",
@ -360,6 +361,21 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "futures"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab30e97ab6aacfe635fad58f22c2bb06c8b685f7421eb1e064a729e2a5f481fa"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]] [[package]]
name = "futures-channel" name = "futures-channel"
version = "0.3.23" version = "0.3.23"
@ -367,6 +383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bfc52cbddcfd745bf1740338492bb0bd83d76c67b445f91c5fb29fae29ecaa1" checksum = "2bfc52cbddcfd745bf1740338492bb0bd83d76c67b445f91c5fb29fae29ecaa1"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-sink",
] ]
[[package]] [[package]]
@ -421,9 +438,11 @@ version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0828a5471e340229c11c77ca80017937ce3c58cb788a17e5f1c2d5c485a9577" checksum = "f0828a5471e340229c11c77ca80017937ce3c58cb788a17e5f1c2d5c485a9577"
dependencies = [ dependencies = [
"futures-channel",
"futures-core", "futures-core",
"futures-io", "futures-io",
"futures-macro", "futures-macro",
"futures-sink",
"futures-task", "futures-task",
"memchr", "memchr",
"pin-project-lite", "pin-project-lite",

1
axumtest/Cargo.toml

@ -7,6 +7,7 @@ edition = "2021"
axum = { version = "0.5.15", features = ["headers"] } axum = { version = "0.5.15", features = ["headers"] }
clap = { version = "3.2.17", features = ["derive", "env"] } clap = { version = "3.2.17", features = ["derive", "env"] }
dotenv = "0.15.0" dotenv = "0.15.0"
futures = "0.3.23"
mongodb = "2.3.0" mongodb = "2.3.0"
serde = { version = "1.0.143", features = ["derive"] } serde = { version = "1.0.143", features = ["derive"] }
serde_json = "1.0.83" serde_json = "1.0.83"

40
axumtest/src/cases/mod.rs

@ -0,0 +1,40 @@
//! Deal with cases.
use std::sync::Arc;
use axum::extract::Path;
use axum::middleware;
use axum::routing::get;
use axum::Router;
use futures::stream::TryStreamExt;
use mongodb::bson::Document;
use crate::auth;
use crate::State;
/// Build the routes for the cases resource.
pub fn router(state: Arc<State>, ci_usr: String, ci_pwd: String, ci_role: String) -> Router {
Router::new().route(
"/collections/:collname/cases",
get({
let shared_state = Arc::clone(&state);
move |path| all_cases_on_collection(path, shared_state)
})
.route_layer(middleware::from_fn(move |req, next| {
let ci_usr = ci_usr.clone();
let ci_pwd = ci_pwd.clone();
let ci_role = ci_role.clone();
auth::ci_auth(req, next, ci_usr, ci_pwd, ci_role)
})),
)
}
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"));
}
format!("Cases!")
}

7
axumtest/src/main.rs

@ -1,4 +1,5 @@
mod auth; mod auth;
mod cases;
mod collections; mod collections;
use std::sync::Arc; use std::sync::Arc;
@ -54,6 +55,12 @@ async fn main() {
args.ci_usr.clone(), args.ci_usr.clone(),
args.ci_pwd.clone(), args.ci_pwd.clone(),
args.ci_role.clone(), args.ci_role.clone(),
))
.merge(cases::router(
state.clone(),
args.ci_usr.clone(),
args.ci_pwd.clone(),
args.ci_role.clone(),
)); ));
tracing::info!(args.addr, "Server listening in"); tracing::info!(args.addr, "Server listening in");

Loading…
Cancel
Save