workflows
This commit is contained in:
parent
6f9048e5b1
commit
a8dfe5f0e9
7 changed files with 119 additions and 8 deletions
46
src/routes/flow.rs
Normal file
46
src/routes/flow.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
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))
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
use std::{collections::HashMap, ops::Deref};
|
||||
|
||||
use mongod::ToAPI;
|
||||
use mongod::{vec_to_api, ToAPI};
|
||||
use rocket::{get, State};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -10,6 +10,7 @@ use crate::{
|
|||
json_store::JSONStore,
|
||||
location::Location,
|
||||
routes::{api_error, FallibleApiResponse, Token},
|
||||
transaction::Transaction,
|
||||
};
|
||||
|
||||
#[get("/location/<id>")]
|
||||
|
@ -99,15 +100,27 @@ pub async fn locations_info(
|
|||
Ok(serde_json::to_value(location_api).unwrap())
|
||||
}
|
||||
|
||||
#[get("/location/<location>/inventory")]
|
||||
#[get("/location/<location>/inventory?<recursive>")]
|
||||
pub async fn location_inventory(
|
||||
location: &str,
|
||||
t: Token,
|
||||
locations: &State<JSONStore<Location>>,
|
||||
c: &State<Config>,
|
||||
recursive: Option<&str>,
|
||||
) -> FallibleApiResponse {
|
||||
check_auth!(t, c);
|
||||
|
||||
// todo : inventory
|
||||
unimplemented!()
|
||||
if let Some(rec) = recursive {
|
||||
match rec {
|
||||
"true" | "yes" | "1" => {
|
||||
return Ok(json!(
|
||||
vec_to_api(&Transaction::in_location_recursive(location).await).await
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(json!(
|
||||
vec_to_api(&Transaction::in_location(location).await).await
|
||||
))
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use rocket::{
|
|||
};
|
||||
use serde_json::json;
|
||||
|
||||
pub mod flow;
|
||||
pub mod item;
|
||||
|
||||
type ApiError = BadRequest<serde_json::Value>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue