diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-28 16:35:11 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-28 16:35:11 +0100 |
| commit | 5dd3eb56474bc9106df764b5f46625c0787a4ba2 (patch) | |
| tree | 319367f617f264bd61f327e4ea3c41c83deb1f96 /crates/rocie-cli/src/handle/mod.rs | |
| parent | feat(crates/rocie-server): Get closer to feature parity between rocie and grocy (diff) | |
| download | server-5dd3eb56474bc9106df764b5f46625c0787a4ba2.zip | |
feat(crates/rocie-cli): Add support for product parents
Diffstat (limited to 'crates/rocie-cli/src/handle/mod.rs')
| -rw-r--r-- | crates/rocie-cli/src/handle/mod.rs | 31 |
1 files changed, 12 insertions, 19 deletions
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!(); |
