cdb/src/routes/flow.rs

45 lines
896 B
Rust
Raw Normal View History

2024-09-12 10:34:14 +02:00
use std::collections::HashMap;
2024-09-12 11:54:52 +02:00
use mongod::ToAPI;
2024-09-12 10:34:14 +02:00
use rocket::{get, State};
use serde_json::json;
use crate::{
check_auth,
config::Config,
flow::FlowInfo,
json_store::JSONStore,
routes::{api_error, FallibleApiResponse, Token},
};
#[get("/flow/<id>/info")]
pub async fn flow_info(
id: &str,
flows: &State<JSONStore<FlowInfo>>,
t: Token,
c: &State<Config>,
) -> FallibleApiResponse {
check_auth!(t, c);
let flowinfo = flows.get(id).ok_or_else(|| api_error("Flow not found"))?;
Ok(flowinfo.api().await)
}
#[get("/flows")]
pub async fn flows_list(
flows: &State<JSONStore<FlowInfo>>,
t: Token,
c: &State<Config>,
) -> FallibleApiResponse {
check_auth!(t, c);
let mut ret = HashMap::<String, serde_json::Value>::new();
for l in flows.iter() {
ret.insert(l.0.clone(), l.1.api().await);
}
Ok(json!(ret))
}