about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rocie-cli/src/handle/mod.rs57
-rw-r--r--crates/rocie-server/src/api/get/inventory.rs6
-rw-r--r--crates/rocie-server/src/api/get/product.rs6
-rw-r--r--crates/rocie-server/src/api/get/unit.rs6
-rw-r--r--crates/rocie-server/src/api/set/barcode.rs10
-rw-r--r--crates/rocie-server/src/api/set/product.rs6
-rw-r--r--crates/rocie-server/src/storage/sql/barcode.rs30
-rw-r--r--crates/rocie-server/src/storage/sql/product.rs32
-rw-r--r--crates/rocie-server/src/storage/sql/unit.rs31
-rw-r--r--crates/rocie-server/tests/products/barcode.rs62
-rw-r--r--crates/rocie-server/tests/products/mod.rs26
-rw-r--r--crates/rocie-server/tests/products/register.rs2
12 files changed, 173 insertions, 101 deletions
diff --git a/crates/rocie-cli/src/handle/mod.rs b/crates/rocie-cli/src/handle/mod.rs
index c39f7b1..fc6f137 100644
--- a/crates/rocie-cli/src/handle/mod.rs
+++ b/crates/rocie-cli/src/handle/mod.rs
@@ -11,7 +11,7 @@ use rocie_client::{
         api_set_unit_api::register_unit,
         configuration::Configuration,
     },
-    models::{Barcode, UnitAmount, UnitStub},
+    models::{Barcode, BarcodeId, ProductId, UnitAmount, UnitId, UnitStub},
 };
 
 pub(crate) async fn product(config: &Configuration, command: ProductCommand) -> Result<()> {
@@ -26,7 +26,7 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
                 rocie_client::models::ProductStub {
                     description: Some(description), // TODO: Fix the duplicate option
                     name,
-                    parent,
+                    parent: Some(parent.map(|p| ProductId { value: p })),
                 },
             )
             .await
@@ -36,7 +36,7 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
         }
 
         ProductCommand::Get { id } => {
-            let product = product_by_id(config, id.to_string().as_str())
+            let product = product_by_id(config, ProductId { value: id })
                 .await
                 .with_context(|| format!("Failed to get product with id: {id}"))?;
 
@@ -51,20 +51,30 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
         } => {
             associate_barcode(
                 config,
-                product_id.to_string().as_str(),
+                ProductId { value: product_id },
                 Barcode {
-                    id: i32::try_from(barcode_number).unwrap(),
-                    amount: Box::new(UnitAmount {
-                        unit: amount_unit_id,
-                        value: i64::from(amount_value),
-                    }),
+                    id: BarcodeId {
+                        value: barcode_number,
+                    },
+                    amount: UnitAmount {
+                        unit: UnitId {
+                            value: amount_unit_id,
+                        },
+                        value: amount_value,
+                    },
                 },
             )
             .await
             .context("Failed to associated barcode")?;
 
-            let unit = unit_by_id(config, amount_unit_id.to_string().as_str()).await?;
-            let product = product_by_id(config, product_id.to_string().as_str()).await?;
+            let unit = unit_by_id(
+                config,
+                UnitId {
+                    value: amount_unit_id,
+                },
+            )
+            .await?;
+            let product = product_by_id(config, ProductId { value: product_id }).await?;
 
             println!(
                 "Associated barcode ({barcode_number} - {amount_value} {}) with product: {} ",
@@ -81,16 +91,17 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
                 print!("{}: {}", product.name, product.id);
 
                 {
-                    let product_amount = amount_by_id(config, product.id.to_string().as_str())
-                        .await
-                        .with_context(|| {
+                    let product_amount =
+                        amount_by_id(config, product.id).await.with_context(|| {
                             format!("Failed to get amount of product: {}", product.id)
                         })?;
 
-                    let unit =
-                        unit_by_id(config, product_amount.amount.unit.to_string().as_str()).await?;
+                    let unit = unit_by_id(config, product_amount.amount.unit).await?;
 
-                    print!(" available: {} {}", product_amount.amount.value, unit.short_name);
+                    print!(
+                        " available: {} {}",
+                        product_amount.amount.value, unit.short_name
+                    );
                 }
 
                 if let Some(description) = product
@@ -107,7 +118,7 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
                 }
 
                 for barcode in product.associated_bar_codes {
-                    let unit = unit_by_id(config, barcode.amount.unit.to_string().as_str()).await?;
+                    let unit = unit_by_id(config, barcode.amount.unit).await?;
 
                     println!(
                         "    - {}: {} {}",
@@ -129,7 +140,7 @@ pub(crate) async fn product(config: &Configuration, command: ProductCommand) ->
 pub(crate) async fn barcode(config: &Configuration, command: BarcodeCommand) -> Result<()> {
     match command {
         BarcodeCommand::Buy { id } => {
-            buy_barcode(config, i32::try_from(id).unwrap()).await?;
+            buy_barcode(config, BarcodeId { value: id }).await?;
         }
         BarcodeCommand::Consume {
             id,
@@ -138,10 +149,10 @@ pub(crate) async fn barcode(config: &Configuration, command: BarcodeCommand) ->
         } => {
             consume_barcode(
                 config,
-                i32::try_from(id).unwrap(),
+                BarcodeId { value: id },
                 UnitAmount {
-                    unit: unit_id,
-                    value: i64::from(amount),
+                    unit: UnitId { value: unit_id },
+                    value: amount,
                 },
             )
             .await?;
@@ -188,7 +199,7 @@ pub(crate) async fn unit(config: &Configuration, command: UnitCommand) -> Result
             }
         }
         UnitCommand::GetById { id } => {
-            let unit = unit_by_id(config, id.to_string().as_str())
+            let unit = unit_by_id(config, UnitId { value: id })
                 .await
                 .context("Failed to find unit")?;
             println!(
diff --git a/crates/rocie-server/src/api/get/inventory.rs b/crates/rocie-server/src/api/get/inventory.rs
index 3011430..d1ca436 100644
--- a/crates/rocie-server/src/api/get/inventory.rs
+++ b/crates/rocie-server/src/api/get/inventory.rs
@@ -2,7 +2,7 @@ use actix_web::{HttpResponse, Responder, Result, get, web};
 
 use crate::{
     app::App,
-    storage::sql::{product::ProductId, product_amount::ProductAmount},
+    storage::sql::{product::{ProductId, ProductIdStub}, product_amount::ProductAmount},
 };
 
 /// Get the amount of an product
@@ -33,11 +33,11 @@ use crate::{
 #[get("/inventory/{id}")]
 pub(crate) async fn amount_by_id(
     app: web::Data<App>,
-    id: web::Path<ProductId>,
+    id: web::Path<ProductIdStub>,
 ) -> Result<impl Responder> {
     let id = id.into_inner();
 
-    match ProductAmount::from_id(&app, id).await? {
+    match ProductAmount::from_id(&app, id.into()).await? {
         Some(product) => Ok(HttpResponse::Ok().json(product)),
         None => Ok(HttpResponse::NotFound().finish()),
     }
diff --git a/crates/rocie-server/src/api/get/product.rs b/crates/rocie-server/src/api/get/product.rs
index c496777..90cb8c8 100644
--- a/crates/rocie-server/src/api/get/product.rs
+++ b/crates/rocie-server/src/api/get/product.rs
@@ -2,7 +2,7 @@ use actix_web::{HttpResponse, Responder, Result, get, web};
 
 use crate::{
     app::App,
-    storage::sql::product::{Product, ProductId},
+    storage::sql::product::{Product, ProductId, ProductIdStub},
 };
 
 /// Get Product by id
@@ -19,11 +19,11 @@ use crate::{
 #[get("/product/{id}")]
 pub(crate) async fn product_by_id(
     app: web::Data<App>,
-    id: web::Path<ProductId>,
+    id: web::Path<ProductIdStub>,
 ) -> Result<impl Responder> {
     let id = id.into_inner();
 
-    match Product::from_id(&app, id).await? {
+    match Product::from_id(&app, id.into()).await? {
         Some(product) => Ok(HttpResponse::Ok().json(product)),
         None => Ok(HttpResponse::NotFound().finish()),
     }
diff --git a/crates/rocie-server/src/api/get/unit.rs b/crates/rocie-server/src/api/get/unit.rs
index d006818..4854ea3 100644
--- a/crates/rocie-server/src/api/get/unit.rs
+++ b/crates/rocie-server/src/api/get/unit.rs
@@ -1,6 +1,6 @@
 use actix_web::{get, web, HttpResponse, Responder, Result};
 
-use crate::{app::App, storage::sql::unit::{Unit, UnitId}};
+use crate::{app::App, storage::sql::unit::{Unit, UnitId, UnitIdStub}};
 
 /// Return all registered units
 #[utoipa::path(
@@ -30,11 +30,11 @@ pub(crate) async fn units(app: web::Data<App>) -> Result<impl Responder> {
 #[get("/unit/{id}")]
 pub(crate) async fn unit_by_id(
     app: web::Data<App>,
-    id: web::Path<UnitId>,
+    id: web::Path<UnitIdStub>,
 ) -> Result<impl Responder> {
     let id = id.into_inner();
 
-    match Unit::from_id(&app, id).await? {
+    match Unit::from_id(&app, id.into()).await? {
         Some(product) => Ok(HttpResponse::Ok().json(product)),
         None => Ok(HttpResponse::NotFound().finish()),
     }
diff --git a/crates/rocie-server/src/api/set/barcode.rs b/crates/rocie-server/src/api/set/barcode.rs
index a89bf4f..60b1650 100644
--- a/crates/rocie-server/src/api/set/barcode.rs
+++ b/crates/rocie-server/src/api/set/barcode.rs
@@ -4,7 +4,7 @@ use log::debug;
 use crate::{
     app::App,
     storage::sql::{
-        barcode::{Barcode, BarcodeId, UnitAmount},
+        barcode::{Barcode, BarcodeId, BarcodeIdStub, UnitAmount},
         insert::Operations,
     },
 };
@@ -33,11 +33,11 @@ use crate::{
 #[post("/barcode/{id}/buy")]
 pub(crate) async fn buy_barcode(
     app: web::Data<App>,
-    barcode_id: web::Path<BarcodeId>,
+    barcode_id: web::Path<BarcodeIdStub>,
 ) -> Result<impl Responder> {
     let mut ops = Operations::new("buy barcode unit");
 
-    let barcode = Barcode::from_id(&app, barcode_id.into_inner()).await?;
+    let barcode = Barcode::from_id(&app, barcode_id.into_inner().into()).await?;
 
     match barcode {
         Some(barcode) => {
@@ -76,12 +76,12 @@ pub(crate) async fn buy_barcode(
 #[post("/barcode/{id}/consume")]
 pub(crate) async fn consume_barcode(
     app: web::Data<App>,
-    barcode_id: web::Path<BarcodeId>,
+    barcode_id: web::Path<BarcodeIdStub>,
     unit_amount: web::Json<UnitAmount>,
 ) -> Result<impl Responder> {
     let mut ops = Operations::new("consume barcode unit");
 
-    let barcode = Barcode::from_id(&app, barcode_id.into_inner()).await?;
+    let barcode = Barcode::from_id(&app, barcode_id.into_inner().into()).await?;
     debug!("Starting consume for barcode: {barcode:?}");
 
     match barcode {
diff --git a/crates/rocie-server/src/api/set/product.rs b/crates/rocie-server/src/api/set/product.rs
index 19024c7..d347ee7 100644
--- a/crates/rocie-server/src/api/set/product.rs
+++ b/crates/rocie-server/src/api/set/product.rs
@@ -7,7 +7,7 @@ use crate::{
     storage::sql::{
         barcode::Barcode,
         insert::Operations,
-        product::{Product, ProductId},
+        product::{Product, ProductId, ProductIdStub},
         unit::Unit,
     },
 };
@@ -84,7 +84,7 @@ pub(crate) async fn register_product(
 #[post("/product/{id}/associate")]
 pub(crate) async fn associate_barcode(
     app: web::Data<App>,
-    id: web::Path<ProductId>,
+    id: web::Path<ProductIdStub>,
     barcode: web::Json<Barcode>,
 ) -> Result<impl Responder> {
     let mut ops = Operations::new("associated barcode with product");
@@ -97,7 +97,7 @@ pub(crate) async fn associate_barcode(
         }
     }
 
-    match Product::from_id(&app, id.into_inner()).await? {
+    match Product::from_id(&app, id.into_inner().into()).await? {
         Some(product) => {
             product.associate_barcode(barcode.into_inner(), &mut ops);
 
diff --git a/crates/rocie-server/src/storage/sql/barcode.rs b/crates/rocie-server/src/storage/sql/barcode.rs
index 239ed8c..1c3c55a 100644
--- a/crates/rocie-server/src/storage/sql/barcode.rs
+++ b/crates/rocie-server/src/storage/sql/barcode.rs
@@ -5,26 +5,46 @@ use crate::storage::sql::unit::UnitId;
 
 #[derive(ToSchema, Debug, Clone, Serialize, Deserialize)]
 pub(crate) struct Barcode {
-    #[schema(format = Int64, minimum = 0)]
     pub(crate) id: BarcodeId,
     pub(crate) amount: UnitAmount,
 }
 
 #[derive(ToSchema, Debug, Clone, Copy, Serialize, Deserialize)]
-pub(crate) struct BarcodeId(u32);
+pub(crate) struct BarcodeId {
+    #[schema(minimum = 0)]
+    pub(crate) value: u32,
+}
+#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
+#[serde(from = "u32")]
+pub(crate) struct BarcodeIdStub {
+    value: u32,
+}
 
 impl BarcodeId {
     pub(crate) fn to_db(self) -> i64 {
-        i64::from(self.0)
+        i64::from(self.value)
     }
     pub(crate) fn from_db(val: i64) -> Self {
-        Self(u32::try_from(val).expect("Should be strictly positive"))
+        Self {
+            value: u32::try_from(val).expect("Should be strictly positive"),
+        }
+    }
+}
+
+impl From<u32> for BarcodeIdStub {
+    fn from(value: u32) -> Self {
+        Self { value }
+    }
+}
+impl From<BarcodeIdStub> for BarcodeId {
+    fn from(value: BarcodeIdStub) -> Self {
+        Self { value: value.value }
     }
 }
 
 #[derive(ToSchema, Debug, Clone, Copy, Serialize, Deserialize)]
 pub(crate) struct UnitAmount {
-    #[schema(format = Int64, minimum = 0)]
+    #[schema(minimum = 0)]
     pub(crate) value: u32,
     pub(crate) unit: UnitId,
 }
diff --git a/crates/rocie-server/src/storage/sql/product.rs b/crates/rocie-server/src/storage/sql/product.rs
index 93cc6a0..c94fcce 100644
--- a/crates/rocie-server/src/storage/sql/product.rs
+++ b/crates/rocie-server/src/storage/sql/product.rs
@@ -18,23 +18,45 @@ pub(crate) struct Product {
 #[derive(
     Deserialize, Serialize, Debug, Default, ToSchema, Clone, Copy, PartialEq, Eq, PartialOrd, Ord,
 )]
-pub(crate) struct ProductId(Uuid);
+pub(crate) struct ProductId {
+    value: Uuid,
+}
+
+#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
+#[serde(from = "Uuid")]
+pub(crate) struct ProductIdStub {
+    value: Uuid,
+}
 
 impl ProductId {
     pub(crate) fn from_db(id: &str) -> ProductId {
-        Self(Uuid::from_str(id).expect("We put an uuid into the db, it should also go out again"))
+        Self {
+            value: Uuid::from_str(id)
+                .expect("We put an uuid into the db, it should also go out again"),
+        }
     }
 }
 
 impl Display for ProductId {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.0)
+        write!(f, "{}", self.value)
     }
 }
 
 impl From<Uuid> for ProductId {
     fn from(value: Uuid) -> Self {
-        Self(value)
+        Self { value }
+    }
+}
+
+impl From<Uuid> for ProductIdStub {
+    fn from(value: Uuid) -> Self {
+        Self { value }
+    }
+}
+impl From<ProductIdStub> for ProductId {
+    fn from(value: ProductIdStub) -> Self {
+        Self { value: value.value }
     }
 }
 
@@ -46,7 +68,7 @@ where
         &self,
         buf: &mut <DB as Database>::ArgumentBuffer<'q>,
     ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
-        let inner = self.0.to_string();
+        let inner = self.value.to_string();
         Encode::<DB>::encode_by_ref(&inner, buf)
     }
 }
diff --git a/crates/rocie-server/src/storage/sql/unit.rs b/crates/rocie-server/src/storage/sql/unit.rs
index fe00b1b..77e7a2e 100644
--- a/crates/rocie-server/src/storage/sql/unit.rs
+++ b/crates/rocie-server/src/storage/sql/unit.rs
@@ -17,23 +17,44 @@ pub(crate) struct Unit {
 #[derive(
     Deserialize, Serialize, Debug, Default, ToSchema, Clone, Copy, PartialEq, Eq, PartialOrd, Ord,
 )]
-pub(crate) struct UnitId(Uuid);
+pub(crate) struct UnitId {
+    value: Uuid,
+}
+
+#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
+#[serde(from = "Uuid")]
+pub(crate) struct UnitIdStub {
+    value: Uuid,
+}
 
 impl UnitId {
     pub(crate) fn from_db(id: &str) -> UnitId {
-        Self(Uuid::from_str(id).expect("We put an uuid into the db, it should also go out again"))
+        Self {
+            value: Uuid::from_str(id)
+                .expect("We put an uuid into the db, it should also go out again"),
+        }
     }
 }
 
 impl Display for UnitId {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.0)
+        write!(f, "{}", self.value)
     }
 }
 
 impl From<Uuid> for UnitId {
     fn from(value: Uuid) -> Self {
-        Self(value)
+        Self { value }
+    }
+}
+impl From<Uuid> for UnitIdStub {
+    fn from(value: Uuid) -> Self {
+        Self { value }
+    }
+}
+impl From<UnitIdStub> for UnitId {
+    fn from(value: UnitIdStub) -> Self {
+        Self { value: value.value }
     }
 }
 
@@ -45,7 +66,7 @@ where
         &self,
         buf: &mut <DB as Database>::ArgumentBuffer<'q>,
     ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
-        let inner = self.0.to_string();
+        let inner = self.value.to_string();
         Encode::<DB>::encode_by_ref(&inner, buf)
     }
 }
diff --git a/crates/rocie-server/tests/products/barcode.rs b/crates/rocie-server/tests/products/barcode.rs
index c267006..480dcb9 100644
--- a/crates/rocie-server/tests/products/barcode.rs
+++ b/crates/rocie-server/tests/products/barcode.rs
@@ -3,7 +3,7 @@ use rocie_client::{
         api_get_inventory_api::amount_by_id,
         api_set_barcode_api::{buy_barcode, consume_barcode},
     },
-    models::UnitAmount,
+    models::{BarcodeId, UnitAmount},
 };
 
 use crate::{
@@ -21,31 +21,31 @@ async fn test_barcode_buy() {
     let (unit_id, product_id) =
         create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
 
-    request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+    request!(env, buy_barcode(BarcodeId { value: barcode_id }));
 
-    let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+    let product_amount = request!(env, amount_by_id(product_id));
 
     assert_eq!(product_amount.product_id, product_id);
     assert_eq!(product_amount.amount.unit, unit_id);
-    assert_eq!(product_amount.amount.value, i64::from(unit_value));
+    assert_eq!(product_amount.amount.value, unit_value);
 }
 
 #[tokio::test]
 async fn test_barcode_consume() {
     let env = TestEnv::new(module_path!(), 8083);
 
-    let barcode_id = 23;
+    let barcode_id = BarcodeId { value: 23 };
     let unit_value = 1;
 
     let (unit_id, product_id) =
-        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
 
-    request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+    request!(env, buy_barcode(barcode_id));
 
     request!(
         env,
         consume_barcode(
-            i32::try_from(barcode_id).unwrap(),
+            barcode_id,
             UnitAmount {
                 unit: unit_id,
                 value: 1,
@@ -53,7 +53,7 @@ async fn test_barcode_consume() {
         )
     );
 
-    let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+    let product_amount = request!(env, amount_by_id(product_id));
 
     assert_eq!(product_amount.product_id, product_id);
     assert_eq!(product_amount.amount.unit, unit_id);
@@ -64,50 +64,50 @@ async fn test_barcode_consume() {
 async fn test_barcode_consume_error() {
     let env = TestEnv::new(module_path!(), 8084);
 
-    let barcode_id = 23;
+    let barcode_id = BarcodeId { value: 23 };
     let unit_value = 1;
 
     let (unit_id, product_id) =
-        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
 
-    request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+    request!(env, buy_barcode(barcode_id));
 
     request!(
         @expect_error "We should not be able to consume more than available."
         env,
         consume_barcode(
-            i32::try_from(barcode_id).unwrap(),
+            barcode_id,
             UnitAmount {
                 unit: unit_id,
-                value: i64::from(unit_value + 1),
+                value: unit_value + 1,
             },
         )
     );
 
     // Test, that the error does not actually go into the db.
-    let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+    let product_amount = request!(env, amount_by_id(product_id));
 
     assert_eq!(product_amount.product_id, product_id);
     assert_eq!(product_amount.amount.unit, unit_id);
-    assert_eq!(product_amount.amount.value, i64::from(unit_value));
+    assert_eq!(product_amount.amount.value, unit_value);
 }
 
 #[tokio::test]
 async fn test_barcode_consume_error_other() {
     let env = TestEnv::new(module_path!(), 8085);
 
-    let barcode_id = 23;
+    let barcode_id = BarcodeId { value: 23 };
     let unit_value = 1;
 
     let (unit_id, product_id) =
-        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
 
-    request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+    request!(env, buy_barcode(barcode_id));
 
     request!(
         env,
         consume_barcode(
-            i32::try_from(barcode_id).unwrap(),
+            barcode_id,
             UnitAmount {
                 unit: unit_id,
                 value: 1,
@@ -119,7 +119,7 @@ async fn test_barcode_consume_error_other() {
         @expect_error "We already consumed everything, we bought"
         env,
         consume_barcode(
-            i32::try_from(barcode_id).unwrap(),
+            barcode_id,
             UnitAmount {
                 unit: unit_id,
                 value: 1,
@@ -128,33 +128,33 @@ async fn test_barcode_consume_error_other() {
     );
 
     // Test, that the error does not actually go into the db.
-    let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+    let product_amount = request!(env, amount_by_id(product_id));
 
     assert_eq!(product_amount.product_id, product_id);
     assert_eq!(product_amount.amount.unit, unit_id);
-    assert_eq!(product_amount.amount.value, i64::from(0));
+    assert_eq!(product_amount.amount.value, 0);
 }
 
 #[tokio::test]
 async fn test_barcode_multiple_buy_and_consume() {
     let env = TestEnv::new(module_path!(), 8086);
 
-    let barcode_id = 23;
+    let barcode_id = BarcodeId { value: 23 };
     let unit_value = 1;
 
     let (unit_id, product_id) =
-        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+        create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
 
-    request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+    request!(env, buy_barcode(barcode_id));
 
-    request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+    request!(env, buy_barcode(barcode_id));
 
     env.log("Bought both barcodes");
 
     request!(
         env,
         consume_barcode(
-            i32::try_from(barcode_id).unwrap(),
+            barcode_id,
             UnitAmount {
                 unit: unit_id,
                 value: 1,
@@ -167,7 +167,7 @@ async fn test_barcode_multiple_buy_and_consume() {
     request!(
         env,
         consume_barcode(
-            i32::try_from(barcode_id).unwrap(),
+            barcode_id,
             UnitAmount {
                 unit: unit_id,
                 value: 1,
@@ -177,9 +177,9 @@ async fn test_barcode_multiple_buy_and_consume() {
 
     env.log("Consumed second barcode");
 
-    let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+    let product_amount = request!(env, amount_by_id(product_id));
 
     assert_eq!(product_amount.product_id, product_id);
     assert_eq!(product_amount.amount.unit, unit_id);
-    assert_eq!(product_amount.amount.value, i64::from(0));
+    assert_eq!(product_amount.amount.value, 0);
 }
diff --git a/crates/rocie-server/tests/products/mod.rs b/crates/rocie-server/tests/products/mod.rs
index e96ecc9..2ae52fa 100644
--- a/crates/rocie-server/tests/products/mod.rs
+++ b/crates/rocie-server/tests/products/mod.rs
@@ -4,16 +4,15 @@ use rocie_client::{
         api_set_product_api::{associate_barcode, register_product},
         api_set_unit_api::register_unit,
     },
-    models::{Barcode, Product, ProductStub, UnitAmount, UnitStub},
+    models::{Barcode, BarcodeId, Product, ProductId, ProductStub, UnitAmount, UnitId, UnitStub},
 };
-use uuid::Uuid;
 
 use crate::testenv::{TestEnv, log::request};
 
 mod barcode;
 mod register;
 
-async fn create_product(env: &TestEnv, name: &str) -> Uuid {
+async fn create_product(env: &TestEnv, name: &str) -> ProductId {
     request!(
         env,
         register_product(ProductStub {
@@ -23,7 +22,7 @@ async fn create_product(env: &TestEnv, name: &str) -> Uuid {
         },)
     )
 }
-async fn create_unit(env: &TestEnv, name: &str) -> Uuid {
+async fn create_unit(env: &TestEnv, name: &str) -> UnitId {
     request!(
         env,
         register_unit(UnitStub {
@@ -41,20 +40,21 @@ async fn create_associated_barcode(
     product_name: &str,
     barcode_value: u32,
     barcode_id: u32,
-) -> (Uuid, Uuid) {
+) -> (UnitId, ProductId) {
     let unit_id = create_unit(env, unit_name).await;
     let product_id = create_product(env, product_name).await;
+    let barcode_id = BarcodeId { value: barcode_id };
 
     request!(
         env,
         associate_barcode(
-            product_id.to_string().as_str(),
+            product_id,
             Barcode {
-                amount: Box::new(UnitAmount {
+                amount: UnitAmount {
                     unit: unit_id,
-                    value: i64::from(barcode_value),
-                }),
-                id: i32::try_from(barcode_id).unwrap(),
+                    value: barcode_value,
+                },
+                id: barcode_id,
             },
         )
     );
@@ -62,8 +62,6 @@ async fn create_associated_barcode(
     (unit_id, product_id)
 }
 
-async fn get_product(env: &TestEnv, id: Uuid) -> Product {
-    product_by_id(&env.config, id.to_string().as_str())
-        .await
-        .unwrap()
+async fn get_product(env: &TestEnv, id: ProductId) -> Product {
+    product_by_id(&env.config, id).await.unwrap()
 }
diff --git a/crates/rocie-server/tests/products/register.rs b/crates/rocie-server/tests/products/register.rs
index 34f7b5c..15abec4 100644
--- a/crates/rocie-server/tests/products/register.rs
+++ b/crates/rocie-server/tests/products/register.rs
@@ -18,7 +18,7 @@ async fn test_product_register_roundtrip() {
         },)
     );
 
-    let product = request!(env, product_by_id(id.to_string().as_str()));
+    let product = request!(env, product_by_id(id));
 
     assert_eq!(&product.name, "Soy drink");
     assert_eq!(