diff --git a/schema/process.json b/schema/flow.json similarity index 55% rename from schema/process.json rename to schema/flow.json index aeb12ee..3e879ec 100644 --- a/schema/process.json +++ b/schema/flow.json @@ -1,30 +1,30 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Process", - "description": "Process Description", + "title": "Flow", + "description": "Workflow Description", "properties": { "name": { "type": "string", - "title": "Process Name", - "description": "The name of the Process" + "title": "Flow Name", + "description": "The name of the Flow" }, "depends": { "type": "array", - "title": "Process Dependencies", - "description": "List of Items a Process depends on", + "title": "Flow Dependencies", + "description": "List of Items a Flow depends on", "items": { "type": "string" } }, "next": { "type": "string", - "title": "Next Process", - "description": "The Process that succeeds this one." + "title": "Next Flow", + "description": "The Flow that succeeds this one." }, "produces": { "type": "array", "title": "Produced Items", - "description": "Items this Process will produce", + "description": "Items this Flow can produce", "items": { "type": "string" } diff --git a/src/flow.rs b/src/flow.rs new file mode 100644 index 0000000..d177e6d --- /dev/null +++ b/src/flow.rs @@ -0,0 +1,43 @@ +use std::collections::HashMap; + +use mongod::{assert_reference_of, Reference, Validate}; + +pub struct FlowInfo { + pub name: String, + pub depends: HashMap, + pub next: Option, + pub produces: Option>, +} + +use mongod::{ + derive::{Model, Referencable}, + Model, Referencable, ToAPI, +}; +use mongodb::bson::doc; +use serde::{Deserialize, Serialize}; +use serde_json::json; + +/// A production flow +#[derive(Debug, Clone, Serialize, Deserialize, Model, Referencable)] +pub struct Flow { + /// ID + pub _id: String, + /// Tiemstamp when the flow was started + pub started: i64, + /// Timestamp when the flow was ended + pub ended: i64, + /// Kind of flow; ID of the describing JSON + pub kind: String, + /// The flow succedding this one + pub next: Option, +} + +impl Validate for Flow { + async fn validate(&self) -> Result<(), String> { + if let Some(next) = &self.next { + assert_reference_of!(next, Flow); + } + + Ok(()) + } +} diff --git a/src/item.rs b/src/item.rs index d5437c3..a2b68a8 100644 --- a/src/item.rs +++ b/src/item.rs @@ -11,8 +11,6 @@ use serde_json::json; use crate::transaction::Transaction; use crate::variant::Variant; -// todo : api key auth - // ITEM // VARIANTS // QUANTIZATION diff --git a/src/main.rs b/src/main.rs index 7606968..4a68325 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,10 +8,10 @@ use rocket::{http::Method, launch}; mod config; mod db; +mod flow; mod item; mod json_store; mod location; -mod process; mod routes; mod transaction; mod variant; diff --git a/src/process.rs b/src/process.rs deleted file mode 100644 index 704389a..0000000 --- a/src/process.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::collections::HashMap; - -pub struct ProcessInfo { - pub name: String, - pub depends: HashMap, - pub next: Option, - pub produces: Option>, -} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 5242207..4318ab4 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -30,7 +30,7 @@ impl<'r> FromRequest<'r> for Token { type Error = (); async fn from_request(request: &'r Request<'_>) -> rocket::request::Outcome { - match request.headers().get_one("token") { + match request.headers().get_one("Token") { Some(key) => Outcome::Success(Token(key.to_string())), None => Outcome::Error((Status::Unauthorized, ())), }