From d0263ce46160cd4152c67381fab2ee557f3aa483 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 30 Sep 2025 09:15:56 +0200 Subject: feat(treewide): Switch to tailwindcss and add more components --- src/api/mod.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/api/mod.rs (limited to 'src/api/mod.rs') diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 0000000..8b9e77d --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1,50 @@ +use leptos::{ + error::Error, + prelude::{Read, expect_context}, +}; +use reactive_stores::Store; +use rocie_client::{ + apis::{ + api_get_inventory_api::amount_by_id, + api_get_product_api::{product_by_id, products}, + api_get_unit_api::unit_by_id, + }, + models::{Product, ProductAmount, ProductId, Unit, UnitId}, +}; + +use crate::{ConfigState, ConfigStateStoreFields}; + +pub(crate) async fn get_amount_by_id(product_id: ProductId) -> Result { + let config = expect_context::>(); + amount_by_id(&config.config().read(), product_id) + .await + .map_err(Into::::into) +} +pub(crate) async fn get_product_by_id(product_id: ProductId) -> Result { + let config = expect_context::>(); + product_by_id(&config.config().read(), product_id) + .await + .map_err(Into::::into) +} +pub(crate) async fn get_unit_by_id(unit_id: UnitId) -> Result { + let config = expect_context::>(); + unit_by_id(&config.config().read(), unit_id) + .await + .map_err(Into::::into) +} +pub(crate) async fn get_full_product_by_id( + id: ProductId, +) -> Result<(Product, ProductAmount, Unit), Error> { + let amount = get_amount_by_id(id).await?; + let product = get_product_by_id(id).await?; + let unit = get_unit_by_id(amount.amount.unit).await?; + + Ok::<_, Error>((product, amount, unit)) +} + +pub(crate) async fn get_products() -> Result, Error> { + let config = expect_context::>(); + products(&config.config().read()) + .await + .map_err(Into::::into) +} -- cgit 1.4.1