add active flow route

This commit is contained in:
JMARyA 2024-09-19 08:38:37 +02:00
parent 2149217dc2
commit 1271387131
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 47 additions and 1 deletions

View file

@ -1,6 +1,7 @@
use std::collections::HashMap;
use mongod::{Model, Referencable, ToAPI};
use mongod::{vec_to_api, Model, Referencable, ToAPI};
use mongodb::bson::doc;
use rocket::{get, post, serde::json::Json, State};
use serde::{Deserialize, Serialize};
use serde_json::json;
@ -30,6 +31,31 @@ pub async fn flow_info(
Ok(flowinfo.api().await)
}
#[get("/flow/<id>/active")]
pub async fn active_flows_route(
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"))?;
let flow = Flow::find(
doc! {
"kind": flowinfo.reference(),
"done": { "$not": { "$type": "object" } }
},
None,
None,
)
.await
.unwrap();
Ok(json!(vec_to_api(&flow).await))
}
#[get("/flows")]
pub async fn flows_list(
flows: &State<JSONStore<FlowInfo>>,