add active flow route
This commit is contained in:
parent
2149217dc2
commit
1271387131
2 changed files with 47 additions and 1 deletions
20
src/flow.rs
20
src/flow.rs
|
@ -67,6 +67,14 @@ impl DoneInfo {
|
||||||
produced: None,
|
produced: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn api(&self) -> serde_json::Value {
|
||||||
|
json!({
|
||||||
|
"ended": self.ended,
|
||||||
|
"next": self.next.as_ref().map(|x| x.id()),
|
||||||
|
"produced": self.produced.as_ref().map(|x| x.iter().map(|t| t.id()).collect::<Vec<_>>()),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A production flow
|
/// A production flow
|
||||||
|
@ -109,6 +117,18 @@ impl Validate for Flow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToAPI for Flow {
|
||||||
|
async fn api(&self) -> serde_json::Value {
|
||||||
|
json!({
|
||||||
|
"id": self._id,
|
||||||
|
"started": self.started,
|
||||||
|
"kind": self.kind.id(),
|
||||||
|
"input": self.input.as_ref().map(|x| x.iter().map(|t| t.id()).collect::<Vec<_>>()),
|
||||||
|
"done": self.done.as_ref().map(|x| x.api())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Flow {
|
impl Flow {
|
||||||
pub async fn create(kind: &str, input: Option<Vec<Reference>>) -> Self {
|
pub async fn create(kind: &str, input: Option<Vec<Reference>>) -> Self {
|
||||||
let f = Self {
|
let f = Self {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::HashMap;
|
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 rocket::{get, post, serde::json::Json, State};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
@ -30,6 +31,31 @@ pub async fn flow_info(
|
||||||
Ok(flowinfo.api().await)
|
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")]
|
#[get("/flows")]
|
||||||
pub async fn flows_list(
|
pub async fn flows_list(
|
||||||
flows: &State<JSONStore<FlowInfo>>,
|
flows: &State<JSONStore<FlowInfo>>,
|
||||||
|
|
Loading…
Reference in a new issue