about summary refs log tree commit diff stats
path: root/crates/rocie-cli/src/handle/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rocie-cli/src/handle/mod.rs')
-rw-r--r--crates/rocie-cli/src/handle/mod.rs65
1 files changed, 62 insertions, 3 deletions
diff --git a/crates/rocie-cli/src/handle/mod.rs b/crates/rocie-cli/src/handle/mod.rs
index fc6f137..101f56d 100644
--- a/crates/rocie-cli/src/handle/mod.rs
+++ b/crates/rocie-cli/src/handle/mod.rs
@@ -1,4 +1,4 @@
-use crate::cli::{BarcodeCommand, ProductCommand, UnitCommand};
+use crate::cli::{BarcodeCommand, ProductCommand, UnitCommand, UnitPropertyCommand};
 
 use anyhow::{Context, Result};
 use rocie_client::{
@@ -6,12 +6,17 @@ use rocie_client::{
         api_get_inventory_api::amount_by_id,
         api_get_product_api::{product_by_id, products},
         api_get_unit_api::{unit_by_id, units},
+        api_get_unit_property_api::{unit_properties, unit_property_by_id},
         api_set_barcode_api::{buy_barcode, consume_barcode},
         api_set_product_api::{associate_barcode, register_product},
         api_set_unit_api::register_unit,
+        api_set_unit_property_api::register_unit_property,
         configuration::Configuration,
     },
-    models::{Barcode, BarcodeId, ProductId, UnitAmount, UnitId, UnitStub},
+    models::{
+        Barcode, BarcodeId, ProductId, UnitAmount, UnitId, UnitPropertyId, UnitPropertyStub,
+        UnitStub,
+    },
 };
 
 pub(crate) async fn product(config: &Configuration, command: ProductCommand) -> Result<()> {
@@ -20,12 +25,16 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
             name,
             description,
             parent,
+            unit_property,
         } => {
             let new_id = register_product(
                 config,
                 rocie_client::models::ProductStub {
                     description: Some(description), // TODO: Fix the duplicate option
                     name,
+                    unit_property: UnitPropertyId {
+                        value: unit_property,
+                    },
                     parent: Some(parent.map(|p| ProductId { value: p })),
                 },
             )
@@ -169,6 +178,7 @@ pub(crate) async fn unit(config: &Configuration, command: UnitCommand) -> Result
             full_name_plural,
             short_name,
             description,
+            unit_property,
         } => {
             let new_id = register_unit(
                 config,
@@ -177,6 +187,9 @@ pub(crate) async fn unit(config: &Configuration, command: UnitCommand) -> Result
                     full_name_plural,
                     full_name_singular,
                     short_name,
+                    unit_property: UnitPropertyId {
+                        value: unit_property,
+                    },
                 },
             )
             .await
@@ -184,7 +197,7 @@ pub(crate) async fn unit(config: &Configuration, command: UnitCommand) -> Result
             println!("Registered new unit with id: {new_id}");
         }
         UnitCommand::List {} => {
-            let all = units(config).await.context("Failed to get all products")?;
+            let all = units(config).await.context("Failed to get all units")?;
 
             for unit in all {
                 print!("{}: {}", unit.full_name_singular, unit.id);
@@ -211,3 +224,49 @@ pub(crate) async fn unit(config: &Configuration, command: UnitCommand) -> Result
 
     Ok(())
 }
+
+pub(crate) async fn unit_property(
+    config: &Configuration,
+    command: UnitPropertyCommand,
+) -> Result<()> {
+    match command {
+        UnitPropertyCommand::Register { name, description } => {
+            let new_id = register_unit_property(
+                config,
+                UnitPropertyStub {
+                    description: Some(description),
+                    name,
+                },
+            )
+            .await
+            .context("Failed to register unit property")?;
+            println!("Registered new unit property with id: {new_id}");
+        }
+        UnitPropertyCommand::List {} => {
+            let all = unit_properties(config)
+                .await
+                .context("Failed to get all unit properties")?;
+
+            for unit_prop in all {
+                print!("{}: {}", unit_prop.name, unit_prop.id);
+
+                if let Some(description) = unit_prop
+                    .description
+                    .expect("Superflous Option wrapping in api")
+                {
+                    println!(" ({description})");
+                } else {
+                    println!();
+                }
+            }
+        }
+        UnitPropertyCommand::GetById { id } => {
+            let unit = unit_property_by_id(config, UnitPropertyId { value: id })
+                .await
+                .context("Failed to find unit property")?;
+            println!("Unit property: {} ({})", unit.id, unit.name);
+        }
+    }
+
+    Ok(())
+}