about summary refs log tree commit diff stats
path: root/crates/rocie-cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rocie-cli/src')
-rw-r--r--crates/rocie-cli/src/cli.rs29
-rw-r--r--crates/rocie-cli/src/handle/mod.rs31
-rw-r--r--crates/rocie-cli/src/main.rs9
3 files changed, 46 insertions, 23 deletions
diff --git a/crates/rocie-cli/src/cli.rs b/crates/rocie-cli/src/cli.rs
index a683306..626a7b1 100644
--- a/crates/rocie-cli/src/cli.rs
+++ b/crates/rocie-cli/src/cli.rs
@@ -15,6 +15,12 @@ pub(crate) enum Command {
         command: ProductCommand,
     },
 
+    /// Deal with parents
+    Parents {
+        #[command(subcommand)]
+        command: ProductParentCommand,
+    },
+
     /// Deal with units
     Unit {
         #[command(subcommand)]
@@ -35,6 +41,29 @@ pub(crate) enum Command {
 }
 
 #[derive(Subcommand)]
+pub(crate) enum ProductParentCommand {
+    /// Register a new product parent
+    Register {
+        #[arg(short, long)]
+        name: String,
+
+        /// Optional description of the new product parent
+        #[arg(short, long)]
+        description: Option<String>,
+    },
+
+    /// Fetch an product parent based on id
+    GetById {
+        /// The id of the product parent
+        #[arg(short, long)]
+        id: Uuid,
+    },
+
+    /// List all available product parents
+    List {},
+}
+
+#[derive(Subcommand)]
 pub(crate) enum UnitCommand {
     /// Register a new unit
     Register {
diff --git a/crates/rocie-cli/src/handle/mod.rs b/crates/rocie-cli/src/handle/mod.rs
index 929c0ff..4e63696 100644
--- a/crates/rocie-cli/src/handle/mod.rs
+++ b/crates/rocie-cli/src/handle/mod.rs
@@ -4,7 +4,7 @@ use anyhow::{Context, Result};
 use rocie_client::{
     apis::{
         api_get_inventory_api::amount_by_id,
-        api_get_product_api::{product_by_id, products},
+        api_get_product_api::{product_by_id, products_registered},
         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},
@@ -14,11 +14,12 @@ use rocie_client::{
         configuration::Configuration,
     },
     models::{
-        Barcode, BarcodeId, ProductId, UnitAmount, UnitId, UnitPropertyId, UnitPropertyStub,
-        UnitStub,
+        Barcode, BarcodeId, ProductId, ProductParentId, UnitAmount, UnitId, UnitPropertyId,
+        UnitPropertyStub, UnitStub,
     },
 };
 
+#[expect(clippy::too_many_lines)]
 pub(crate) async fn product(config: &Configuration, command: ProductCommand) -> Result<()> {
     match command {
         ProductCommand::Register {
@@ -30,12 +31,12 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
             let new_id = register_product(
                 config,
                 rocie_client::models::ProductStub {
-                    description: Some(description), // TODO: Fix the duplicate option
+                    description,
                     name,
                     unit_property: UnitPropertyId {
                         value: unit_property,
                     },
-                    parent: Some(parent.map(|p| ProductId { value: p })),
+                    parent: parent.map(|p| ProductParentId { value: p }),
                 },
             )
             .await
@@ -92,7 +93,7 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
         }
 
         ProductCommand::List {} => {
-            let all = products(config)
+            let all = products_registered(config)
                 .await
                 .context("Failed to get all products")?;
 
@@ -113,10 +114,7 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
                     );
                 }
 
-                if let Some(description) = product
-                    .description
-                    .expect("Superflous Option wrapping in api")
-                {
+                if let Some(description) = product.description {
                     println!(" ({description})");
                 } else {
                     println!();
@@ -183,7 +181,7 @@ pub(crate) async fn unit(config: &Configuration, command: UnitCommand) -> Result
             let new_id = register_unit(
                 config,
                 UnitStub {
-                    description: Some(description),
+                    description,
                     full_name_plural,
                     full_name_singular,
                     short_name,
@@ -202,9 +200,7 @@ pub(crate) async fn unit(config: &Configuration, command: UnitCommand) -> Result
             for unit in all {
                 print!("{}: {}", unit.full_name_singular, unit.id);
 
-                if let Some(description) =
-                    unit.description.expect("Superflous Option wrapping in api")
-                {
+                if let Some(description) = unit.description {
                     println!(" ({description})");
                 } else {
                     println!();
@@ -234,7 +230,7 @@ pub(crate) async fn unit_property(
             let new_id = register_unit_property(
                 config,
                 UnitPropertyStub {
-                    description: Some(description),
+                    description,
                     name,
                 },
             )
@@ -250,10 +246,7 @@ pub(crate) async fn unit_property(
             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")
-                {
+                if let Some(description) = unit_prop.description {
                     println!(" ({description})");
                 } else {
                     println!();
diff --git a/crates/rocie-cli/src/main.rs b/crates/rocie-cli/src/main.rs
index 26e0f62..2a4eaac 100644
--- a/crates/rocie-cli/src/main.rs
+++ b/crates/rocie-cli/src/main.rs
@@ -15,10 +15,11 @@ async fn main() -> Result<()> {
     "http://127.0.0.1:8080".clone_into(&mut config.base_path);
 
     match args.command {
-        Command::Product { command } => handle::product(&config, command).await?,
-        Command::Unit { command } => handle::unit(&config, command).await?,
-        Command::Barcode { command } => handle::barcode(&config, command).await?,
-        Command::UnitProperty { command } => handle::unit_property(&config, command).await?,
+        Command::Product{command}=>handle::product(&config,command).await?,
+        Command::Unit{command}=>handle::unit(&config,command).await?,
+        Command::Barcode{command}=>handle::barcode(&config,command).await?,
+        Command::UnitProperty{command}=>handle::unit_property(&config,command).await?,
+        Command::Parents { command } => todo!(),
     }
 
     Ok(())