diff --git a/src/flow.rs b/src/flow.rs index 1adeace..1b420b7 100644 --- a/src/flow.rs +++ b/src/flow.rs @@ -182,6 +182,7 @@ impl Flow { Price::zero(), Some(&format!("flow::{}::{}", self.kind.id(), self._id)), None, + None, ) .await; ret.entry(item.item_variant_id().clone()) diff --git a/src/routes/item/mod.rs b/src/routes/item/mod.rs index d01f8a1..f8f5ff8 100644 --- a/src/routes/item/mod.rs +++ b/src/routes/item/mod.rs @@ -42,7 +42,11 @@ pub fn get_items_route(itemdb: &State, t: Token, c: &State) -> F } #[get("/items/stat")] -pub async fn item_stat_route(itemdb: &State, t: Token, c: &State) -> FallibleApiResponse { +pub async fn item_stat_route( + itemdb: &State, + t: Token, + c: &State, +) -> FallibleApiResponse { check_auth!(t, c); let items = itemdb.items(); @@ -60,7 +64,6 @@ pub async fn item_stat_route(itemdb: &State, t: Token, c: &State } } - Ok(json!({ "item_count": item_count, "total_transactions": transaction_count, diff --git a/src/routes/item/supply.rs b/src/routes/item/supply.rs index acb02c3..8b32acf 100644 --- a/src/routes/item/supply.rs +++ b/src/routes/item/supply.rs @@ -21,6 +21,7 @@ pub struct SupplyForm { price: String, origin: Option, location: Option, + note: Option, } /// Route for supply action. Creates a new Transaction for the specified Item Variant. @@ -47,6 +48,7 @@ pub async fn supply_route( .map_err(|()| api_error("Price malformed"))?, form.origin.as_deref(), form.location.as_deref(), + form.note.as_deref(), ) .await; diff --git a/src/transaction.rs b/src/transaction.rs index 84d9965..08df738 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -27,6 +27,8 @@ pub struct Transaction { pub location: Option, /// Info on consumption of the Item pub consumed: Option, + /// Notes on Transaction + pub note: Option, /// Timestamp of the Transaction pub timestamp: i64, } @@ -59,6 +61,7 @@ impl Transaction { price: Price, origin: Option<&str>, location: Option<&str>, + note: Option<&str>, ) -> Self { Self { _id: uuid::Uuid::new_v4().to_string(), @@ -72,6 +75,7 @@ impl Transaction { } else { None }, + note: note.map(|x| x.to_string()), timestamp: chrono::Utc::now().timestamp(), } } @@ -167,6 +171,7 @@ impl mongod::ToAPI for Transaction { "origin": self.origin, "timestamp": self.timestamp, "consumed": self.consumed, + "note": self.note, "expired": self.is_expired().await }) } diff --git a/src/variant.rs b/src/variant.rs index 05f84c6..7e32d95 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -162,8 +162,9 @@ impl Variant { price: Price, origin: Option<&str>, location: Option<&str>, + note: Option<&str>, ) -> Transaction { - let t = Transaction::new(&self.item, &self.variant, price, origin, location).await; + let t = Transaction::new(&self.item, &self.variant, price, origin, location, note).await; t.insert().await.unwrap();