about summary refs log tree commit diff stats
path: root/crates/rocie-server/src/storage
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-23 22:06:01 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-23 22:06:01 +0200
commit1a7f887451faee3083f5bbf55979665a4e6bc7f4 (patch)
treeba8c78f52495de25810777f880881761122feef5 /crates/rocie-server/src/storage
parentchore(crates/rocie-client): Re-generate (diff)
downloadserver-1a7f887451faee3083f5bbf55979665a4e6bc7f4.zip
feat(crates/rocie-server/api/get-product-{by-name,by-part-name}): Init
Diffstat (limited to 'crates/rocie-server/src/storage')
-rw-r--r--crates/rocie-server/src/storage/sql/get/product/mod.rs25
-rw-r--r--crates/rocie-server/src/storage/sql/product.rs2
2 files changed, 26 insertions, 1 deletions
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<Option<Self>, 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<Vec<Self>, 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<String>,