cdb/src/routes/flow.rs
2024-09-12 10:34:14 +02:00

46 lines
964 B
Rust

use std::collections::HashMap;
use mongod::{vec_to_api, ToAPI};
use rocket::{get, State};
use serde_json::json;
use crate::{
check_auth,
config::Config,
flow::FlowInfo,
json_store::JSONStore,
location::Location,
routes::{api_error, FallibleApiResponse, Token},
transaction::Transaction,
};
#[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))
}