update
Some checks are pending
ci/woodpecker/push/build Pipeline is pending

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

@ -27,6 +27,6 @@ CREATE TABLE transactions (
"location" TEXT,
note TEXT,
destination TEXT,
consumed_price NUMERIC(2),
consumed_price DOUBLE PRECISION,
consumed_timestamp timestamptz
);

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

View file

@ -141,41 +141,44 @@ async fn rocket() -> _ {
integrity::verify_integrity(&config, &flows, &locations, &itemdb).await;
rocket::build()
.mount("/", route![
routes::item::get_items_route,
routes::item::item_route,
routes::item::item_variants_page,
routes::item::supply_log_route,
routes::item::demand_log_route,
routes::item::supply_route,
routes::item::demand_route,
routes::item::transaction_route,
routes::item::inventory_route,
routes::item::inventory_route_variant,
routes::item::variant_stat_route,
routes::item::unique_field_route,
routes::item::location_info,
routes::item::locations_info,
routes::item::locations_list,
routes::item::location_inventory,
routes::flow::flow_info,
routes::flow::flows_list,
routes::item::expired_items_route,
routes::item::min_items_route,
routes::item::variant_price_history_by_origin,
routes::flow::end_flow_route,
routes::flow::continue_flow_route,
routes::flow::create_flow_route,
routes::item::location_condition_warn,
routes::item::move_transaction_route,
routes::item::variant_price_latest_by_origin,
routes::item::item_stat_route,
routes::flow::active_flows_route,
routes::flow::flow_api_route,
routes::flow::create_flow_note_route,
routes::flow::flow_notes_route,
routes::item::item_image_route
])
.mount(
"/",
route![
routes::item::get_items_route,
routes::item::item_route,
routes::item::item_variants_page,
routes::item::supply_log_route,
routes::item::demand_log_route,
routes::item::supply_route,
routes::item::demand_route,
routes::item::transaction_route,
routes::item::inventory_route,
routes::item::inventory_route_variant,
routes::item::variant_stat_route,
routes::item::unique_field_route,
routes::item::location_info,
routes::item::locations_info,
routes::item::locations_list,
routes::item::location_inventory,
routes::flow::flow_info,
routes::flow::flows_list,
routes::item::expired_items_route,
routes::item::min_items_route,
routes::item::variant_price_history_by_origin,
routes::flow::end_flow_route,
routes::flow::continue_flow_route,
routes::flow::create_flow_route,
routes::item::location_condition_warn,
routes::item::move_transaction_route,
routes::item::variant_price_latest_by_origin,
routes::item::item_stat_route,
routes::flow::active_flows_route,
routes::flow::flow_api_route,
routes::flow::create_flow_note_route,
routes::flow::flow_notes_route,
routes::item::item_image_route
],
)
.manage(itemdb)
.manage(locations)
.manage(flows)

View file

@ -22,7 +22,7 @@ pub struct SupplyForm {
pub location: Option<String>,
pub note: Option<String>,
pub quanta: Option<i64>,
pub properties: Option<serde_json::Value>
pub properties: Option<serde_json::Value>,
}
#[post("/supply", data = "<form>")]
@ -50,7 +50,7 @@ pub async fn supply_route(
form.location.as_deref(),
form.note.as_deref(),
form.quanta,
form.properties.clone()
form.properties.clone(),
)
.await;