aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-cli/src/main.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-09-06 18:31:40 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-09-06 18:31:40 +0200
commit1c09b0eb5db415985bfefb52786dbe48d757665e (patch)
treedb1cdbcff8baae9a73fca34e14b52cb8cf7ff230 /crates/rocie-cli/src/main.rs
parentfeat: Provide basic API frame (diff)
downloadserver-1c09b0eb5db415985bfefb52786dbe48d757665e.zip
feat: Provide basic barcode handling support
Diffstat (limited to '')
-rw-r--r--crates/rocie-cli/src/main.rs72
1 files changed, 6 insertions, 66 deletions
diff --git a/crates/rocie-cli/src/main.rs b/crates/rocie-cli/src/main.rs
index f0192d4..ef81ad9 100644
--- a/crates/rocie-cli/src/main.rs
+++ b/crates/rocie-cli/src/main.rs
@@ -1,17 +1,11 @@
-use anyhow::{Context, Result};
+use anyhow::Result;
use clap::Parser;
-use rocie_client::{
- apis::{
- api_get_api::{product_by_id, products},
- api_set_api::{associate_barcode, register_product},
- configuration::Configuration,
- },
- models::{Barcode, UnitAmount},
-};
+use rocie_client::apis::configuration::Configuration;
-use crate::cli::{CliArgs, Command, ProductCommand};
+use crate::cli::{CliArgs, Command};
mod cli;
+mod handle;
#[tokio::main]
async fn main() -> Result<()> {
@@ -21,62 +15,8 @@ async fn main() -> Result<()> {
"http://127.0.0.1:8080".clone_into(&mut config.base_path);
match args.command {
- Command::Product { command } => {
- match command {
- ProductCommand::Register {
- name,
- description,
- parent,
- } => {
- let new_id = register_product(
- &config,
- rocie_client::models::ProductStub {
- description: Some(description), // TODO: Fix
- name,
- parent,
- },
- )
- .await
- .context("Failed to register new product")?;
-
- println!("Registered new product with id: {new_id}");
- }
- ProductCommand::Get { id } => {
- let product = product_by_id(&config, id.to_string().as_str())
- .await
- .with_context(|| format!("Failed to get product with id: {id}"))?;
-
- println!("{product:#?}");
- }
- ProductCommand::AssociateBarcode {
- product_id,
- barcode_number,
- amount_value,
- amount_unit,
- } => associate_barcode(
- &config,
- product_id.to_string().as_str(),
- Barcode {
- amount: Box::new(UnitAmount {
- unit: amount_unit,
- value: amount_value as i32,
- }),
- id: barcode_number as i32,
- },
- )
- .await
- .context("Failed to associated barcode")?,
- ProductCommand::List {} => {
- let all = products(&config)
- .await
- .context("Failed to get all products")?;
-
- for product in all {
- println!("{}: {}", product.name, product.id);
- }
- }
- }
- }
+ Command::Product { command } => handle::product(&config, command).await?,
+ Command::Unit { command } => handle::unit(&config, command).await?,
}
Ok(())