add notes

This commit is contained in:
JMARyA 2024-09-21 01:38:22 +02:00
parent b468aab088
commit 30b6f6a7b3
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 15 additions and 3 deletions

View file

@ -182,6 +182,7 @@ impl Flow {
Price::zero(), Price::zero(),
Some(&format!("flow::{}::{}", self.kind.id(), self._id)), Some(&format!("flow::{}::{}", self.kind.id(), self._id)),
None, None,
None,
) )
.await; .await;
ret.entry(item.item_variant_id().clone()) ret.entry(item.item_variant_id().clone())

View file

@ -42,7 +42,11 @@ pub fn get_items_route(itemdb: &State<ItemDB>, t: Token, c: &State<Config>) -> F
} }
#[get("/items/stat")] #[get("/items/stat")]
pub async fn item_stat_route(itemdb: &State<ItemDB>, t: Token, c: &State<Config>) -> FallibleApiResponse { pub async fn item_stat_route(
itemdb: &State<ItemDB>,
t: Token,
c: &State<Config>,
) -> FallibleApiResponse {
check_auth!(t, c); check_auth!(t, c);
let items = itemdb.items(); let items = itemdb.items();
@ -60,7 +64,6 @@ pub async fn item_stat_route(itemdb: &State<ItemDB>, t: Token, c: &State<Config>
} }
} }
Ok(json!({ Ok(json!({
"item_count": item_count, "item_count": item_count,
"total_transactions": transaction_count, "total_transactions": transaction_count,

View file

@ -21,6 +21,7 @@ pub struct SupplyForm {
price: String, price: String,
origin: Option<String>, origin: Option<String>,
location: Option<String>, location: Option<String>,
note: Option<String>,
} }
/// Route for supply action. Creates a new Transaction for the specified Item Variant. /// 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"))?, .map_err(|()| api_error("Price malformed"))?,
form.origin.as_deref(), form.origin.as_deref(),
form.location.as_deref(), form.location.as_deref(),
form.note.as_deref(),
) )
.await; .await;

View file

@ -27,6 +27,8 @@ pub struct Transaction {
pub location: Option<Reference>, pub location: Option<Reference>,
/// Info on consumption of the Item /// Info on consumption of the Item
pub consumed: Option<Consumed>, pub consumed: Option<Consumed>,
/// Notes on Transaction
pub note: Option<String>,
/// Timestamp of the Transaction /// Timestamp of the Transaction
pub timestamp: i64, pub timestamp: i64,
} }
@ -59,6 +61,7 @@ impl Transaction {
price: Price, price: Price,
origin: Option<&str>, origin: Option<&str>,
location: Option<&str>, location: Option<&str>,
note: Option<&str>,
) -> Self { ) -> Self {
Self { Self {
_id: uuid::Uuid::new_v4().to_string(), _id: uuid::Uuid::new_v4().to_string(),
@ -72,6 +75,7 @@ impl Transaction {
} else { } else {
None None
}, },
note: note.map(|x| x.to_string()),
timestamp: chrono::Utc::now().timestamp(), timestamp: chrono::Utc::now().timestamp(),
} }
} }
@ -167,6 +171,7 @@ impl mongod::ToAPI for Transaction {
"origin": self.origin, "origin": self.origin,
"timestamp": self.timestamp, "timestamp": self.timestamp,
"consumed": self.consumed, "consumed": self.consumed,
"note": self.note,
"expired": self.is_expired().await "expired": self.is_expired().await
}) })
} }

View file

@ -162,8 +162,9 @@ impl Variant {
price: Price, price: Price,
origin: Option<&str>, origin: Option<&str>,
location: Option<&str>, location: Option<&str>,
note: Option<&str>,
) -> Transaction { ) -> 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(); t.insert().await.unwrap();