update
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-06-07 21:30:01 +02:00
parent 16353c7683
commit 581361dde6
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 71 additions and 49 deletions

View file

@ -122,7 +122,7 @@ impl Flow {
info.location.as_ref().map(|x| x.as_str()),
info.note.as_ref().map(|x| x.as_str()),
info.quanta,
info.properties.clone()
info.properties.clone(),
)
.await;
ret.entry(item.item_variant_id().clone())

View file

@ -43,12 +43,12 @@ pub struct Transaction {
pub enum Origin {
Flow(String),
Custom(String)
Custom(String),
}
pub enum Destination {
Flow(String),
Custom(String)
Custom(String),
}
impl Transaction {
@ -60,7 +60,7 @@ impl Transaction {
location: Option<&str>,
note: Option<&str>,
quanta: Option<i64>,
properties: Option<serde_json::Value>
properties: Option<serde_json::Value>,
) -> Self {
sqlx::query_as("INSERT INTO transactions (item, variant, price, origin, location, note, quanta, properties) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *")
.bind(item)
@ -201,7 +201,11 @@ impl Transaction {
impl ToAPI for Transaction {
async fn api(&self) -> serde_json::Value {
let location = if let Some(loc) = &self.location {
Some(get_locations!().get(loc).unwrap().api().await)
if !loc.is_empty() {
Some(get_locations!().get(loc).unwrap().api().await)
} else {
None
}
} else {
None
};

View file

@ -34,8 +34,10 @@ pub fn timestamp_range(year: i32, month: u32) -> (i64, i64) {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Variant {
/// Associated Item
#[serde(default)]
pub item: String,
/// Variant ID
#[serde(default)]
pub variant: String,
/// Variant Name
pub name: String,
@ -50,13 +52,13 @@ pub struct Variant {
/// Custom fields as JSON object schema
pub meta: Option<serde_json::Value>,
/// Quantifiable
pub unit: Option<Quanta>
pub unit: Option<Quanta>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Quanta {
pub by: String,
pub conversions: HashMap<String, f64>
pub conversions: HashMap<String, f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -67,8 +69,11 @@ pub struct VariantNeedCondition {
impl Variant {
/// Create variant from itemdb yaml
pub fn from_yml(json: serde_yaml::Value, variant: &str, item: &str) -> Self {
serde_yaml::from_value(json).unwrap()
pub fn from_yml(json: serde_yaml::Value, variant_str: &str, item: &str) -> Self {
let mut variant: Variant = serde_yaml::from_value(json).unwrap();
variant.item = item.to_string();
variant.variant = variant_str.to_string();
variant
}
/// Get a API id for this Item Variant.
@ -143,9 +148,19 @@ impl Variant {
location: Option<&str>,
note: Option<&str>,
quanta: Option<i64>,
properties: Option<serde_json::Value>
properties: Option<serde_json::Value>,
) -> Transaction {
Transaction::new(&self.item, &self.variant, price, origin, location, note, quanta, properties).await
Transaction::new(
&self.item,
&self.variant,
price,
origin,
location,
note,
quanta,
properties,
)
.await
}
/// Returns all Transactions of this Item Variant