about summary refs log tree commit diff stats
path: root/crates/rocie-server/src/api/set
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-08 11:54:04 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-08 11:54:04 +0200
commit08cf86a44a9a7c513cd12cbc4a0bac7c029b9ded (patch)
tree88b202b25ec22b86f3b4df9f2022b7b23ec3cba1 /crates/rocie-server/src/api/set
parentchore(crates/rocie-client): Regenerate (diff)
downloadserver-08cf86a44a9a7c513cd12cbc4a0bac7c029b9ded.zip
feat(crates/rocie-server/unit-property): Init
Diffstat (limited to 'crates/rocie-server/src/api/set')
-rw-r--r--crates/rocie-server/src/api/set/barcode.rs7
-rw-r--r--crates/rocie-server/src/api/set/mod.rs2
-rw-r--r--crates/rocie-server/src/api/set/product.rs15
-rw-r--r--crates/rocie-server/src/api/set/unit.rs13
-rw-r--r--crates/rocie-server/src/api/set/unit_property.rs47
5 files changed, 79 insertions, 5 deletions
diff --git a/crates/rocie-server/src/api/set/barcode.rs b/crates/rocie-server/src/api/set/barcode.rs
index 60b1650..29eac9e 100644
--- a/crates/rocie-server/src/api/set/barcode.rs
+++ b/crates/rocie-server/src/api/set/barcode.rs
@@ -4,8 +4,9 @@ use log::debug;
 use crate::{
     app::App,
     storage::sql::{
-        barcode::{Barcode, BarcodeId, BarcodeIdStub, UnitAmount},
+        barcode::{Barcode, BarcodeId, BarcodeIdStub},
         insert::Operations,
+        unit::UnitAmount,
     },
 };
 
@@ -86,7 +87,9 @@ pub(crate) async fn consume_barcode(
 
     match barcode {
         Some(barcode) => {
-            barcode.consume(&app, unit_amount.into_inner(), &mut ops).await?;
+            barcode
+                .consume(&app, unit_amount.into_inner(), &mut ops)
+                .await?;
 
             ops.apply(&app).await?;
 
diff --git a/crates/rocie-server/src/api/set/mod.rs b/crates/rocie-server/src/api/set/mod.rs
index a7ddab5..5dd0219 100644
--- a/crates/rocie-server/src/api/set/mod.rs
+++ b/crates/rocie-server/src/api/set/mod.rs
@@ -3,11 +3,13 @@ use actix_web::web;
 pub(crate) mod barcode;
 pub(crate) mod product;
 pub(crate) mod unit;
+pub(crate) mod unit_property;
 
 pub(crate) fn register_paths(cfg: &mut web::ServiceConfig) {
     cfg.service(product::register_product)
         .service(product::associate_barcode)
         .service(unit::register_unit)
+        .service(unit_property::register_unit_property)
         .service(barcode::consume_barcode)
         .service(barcode::buy_barcode);
 }
diff --git a/crates/rocie-server/src/api/set/product.rs b/crates/rocie-server/src/api/set/product.rs
index d347ee7..7372d23 100644
--- a/crates/rocie-server/src/api/set/product.rs
+++ b/crates/rocie-server/src/api/set/product.rs
@@ -9,13 +9,22 @@ use crate::{
         insert::Operations,
         product::{Product, ProductId, ProductIdStub},
         unit::Unit,
+        unit_property::UnitPropertyId,
     },
 };
 
 #[derive(Deserialize, ToSchema)]
 struct ProductStub {
+    /// The name of the product
     name: String,
+
+    /// The Unit Property to use for this product.
+    unit_property: UnitPropertyId,
+
+    /// A description.
     description: Option<String>,
+
+    /// A parent of this product, otherwise the parent will be the root of the parent tree.
     parent: Option<ProductId>,
 }
 
@@ -46,6 +55,7 @@ pub(crate) async fn register_product(
         product_stub.name.clone(),
         product_stub.description.clone(),
         product_stub.parent,
+        product_stub.unit_property,
         &mut ops,
     );
 
@@ -77,7 +87,10 @@ pub(crate) async fn register_product(
         )
     ),
     params (
-        ("id" = ProductId, description = "The id of the product to associated the barcode with"),
+        (
+            "id" = ProductId,
+            description = "The id of the product to associated the barcode with"
+        ),
     ),
     request_body = Barcode,
 )]
diff --git a/crates/rocie-server/src/api/set/unit.rs b/crates/rocie-server/src/api/set/unit.rs
index 4281e05..5f39c8f 100644
--- a/crates/rocie-server/src/api/set/unit.rs
+++ b/crates/rocie-server/src/api/set/unit.rs
@@ -2,13 +2,21 @@ use actix_web::{HttpResponse, Responder, Result, post, web};
 use serde::Deserialize;
 use utoipa::ToSchema;
 
-use crate::{app::App, storage::sql::{insert::Operations, unit::{Unit, UnitId}}};
+use crate::{
+    app::App,
+    storage::sql::{
+        insert::Operations,
+        unit::{Unit, UnitId},
+        unit_property::UnitPropertyId,
+    },
+};
 
 #[derive(Deserialize, ToSchema)]
 struct UnitStub {
     full_name_plural: String,
     full_name_singular: String,
     short_name: String,
+    unit_property: UnitPropertyId,
     description: Option<String>,
 }
 
@@ -17,7 +25,7 @@ struct UnitStub {
     responses(
         (
             status = 200,
-            description = "Product successfully registered in database",
+            description = "Unit successfully registered in database",
             body = UnitId,
         ),
         (
@@ -40,6 +48,7 @@ pub(crate) async fn register_unit(
         unit.full_name_plural.clone(),
         unit.short_name.clone(),
         unit.description.clone(),
+        unit.unit_property,
         &mut ops,
     );
 
diff --git a/crates/rocie-server/src/api/set/unit_property.rs b/crates/rocie-server/src/api/set/unit_property.rs
new file mode 100644
index 0000000..9915e84
--- /dev/null
+++ b/crates/rocie-server/src/api/set/unit_property.rs
@@ -0,0 +1,47 @@
+use actix_web::{HttpResponse, Responder, Result, post, web};
+use serde::Deserialize;
+use utoipa::ToSchema;
+
+use crate::{
+    app::App,
+    storage::sql::{
+        insert::Operations,
+        unit_property::{UnitProperty, UnitPropertyId},
+    },
+};
+
+#[derive(Deserialize, ToSchema)]
+struct UnitPropertyStub {
+    name: String,
+    description: Option<String>,
+}
+
+/// Register an Unit Property
+#[utoipa::path(
+    responses(
+        (
+            status = 200,
+            description = "Unit property successfully registered in database",
+            body = UnitPropertyId,
+        ),
+        (
+            status = INTERNAL_SERVER_ERROR,
+            description = "Server encountered error",
+            body = String,
+        )
+    ),
+    request_body = UnitPropertyStub,
+)]
+#[post("/unit-property/new")]
+pub(crate) async fn register_unit_property(
+    app: web::Data<App>,
+    unit: web::Json<UnitPropertyStub>,
+) -> Result<impl Responder> {
+    let mut ops = Operations::new("register unit property");
+
+    let unit = UnitProperty::register(unit.name.clone(), unit.description.clone(), &mut ops);
+
+    ops.apply(&app).await?;
+
+    Ok(HttpResponse::Ok().json(unit.id))
+}