This commit is contained in:
JMARyA 2024-09-09 21:49:36 +02:00
parent 21fe567ba6
commit e7fe303941
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 54 additions and 21 deletions

View file

@ -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"
}

43
src/flow.rs Normal file
View file

@ -0,0 +1,43 @@
use std::collections::HashMap;
use mongod::{assert_reference_of, Reference, Validate};
pub struct FlowInfo {
pub name: String,
pub depends: HashMap<String, i64>,
pub next: Option<String>,
pub produces: Option<Vec<String>>,
}
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<Reference>,
}
impl Validate for Flow {
async fn validate(&self) -> Result<(), String> {
if let Some(next) = &self.next {
assert_reference_of!(next, Flow);
}
Ok(())
}
}

View file

@ -11,8 +11,6 @@ use serde_json::json;
use crate::transaction::Transaction;
use crate::variant::Variant;
// todo : api key auth
// ITEM
// VARIANTS
// QUANTIZATION

View file

@ -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;

View file

@ -1,8 +0,0 @@
use std::collections::HashMap;
pub struct ProcessInfo {
pub name: String,
pub depends: HashMap<String, i64>,
pub next: Option<String>,
pub produces: Option<Vec<String>>,
}

View file

@ -30,7 +30,7 @@ impl<'r> FromRequest<'r> for Token {
type Error = ();
async fn from_request(request: &'r Request<'_>) -> rocket::request::Outcome<Self, Self::Error> {
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, ())),
}