From 1a7f887451faee3083f5bbf55979665a4e6bc7f4 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 23 Oct 2025 22:06:01 +0200 Subject: feat(crates/rocie-server/api/get-product-{by-name,by-part-name}): Init --- .../src/storage/sql/get/product/mod.rs | 25 ++++++++++++++++++++++ crates/rocie-server/src/storage/sql/product.rs | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'crates/rocie-server/src/storage') diff --git a/crates/rocie-server/src/storage/sql/get/product/mod.rs b/crates/rocie-server/src/storage/sql/get/product/mod.rs index 01047b2..0df51d8 100644 --- a/crates/rocie-server/src/storage/sql/get/product/mod.rs +++ b/crates/rocie-server/src/storage/sql/get/product/mod.rs @@ -36,6 +36,31 @@ impl Product { } } + pub(crate) async fn from_name(app: &App, name: String) -> Result, from_id::Error> { + let record = query!( + " + SELECT name, id, unit_property, description, parent + FROM products + WHERE name = ? +", + name + ) + .fetch_optional(&app.db) + .await?; + + if let Some(record) = record { + Ok(Some(Self { + id: ProductId::from_db(&record.id), + unit_property: UnitPropertyId::from_db(&record.unit_property), + name, + description: record.description, + associated_bar_codes: vec![], // todo + })) + } else { + Ok(None) + } + } + pub(crate) async fn get_all(app: &App) -> Result, get_all::Error> { let records = query!( " diff --git a/crates/rocie-server/src/storage/sql/product.rs b/crates/rocie-server/src/storage/sql/product.rs index 2575b59..1c5a7d8 100644 --- a/crates/rocie-server/src/storage/sql/product.rs +++ b/crates/rocie-server/src/storage/sql/product.rs @@ -20,7 +20,7 @@ pub(crate) struct Product { /// The name of the product. /// /// This should be globally unique, to make searching easier for the user. - pub(super) name: String, + pub(crate) name: String, /// An optional description of this product. pub(super) description: Option, -- cgit 1.4.1