From d45cc8fab35501b6c16f68cac084d861539a3f83 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Wed, 8 Oct 2025 12:01:47 +0200 Subject: feat(crates/rocie-cli): Add support for unit-properties --- crates/rocie-cli/src/handle/mod.rs | 65 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'crates/rocie-cli/src/handle/mod.rs') 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(()) +} -- cgit 1.4.1