about summary refs log tree commit diff stats
path: root/crates/rocie-server/src/storage
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rocie-server/src/storage')
-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
3 files changed, 78 insertions, 15 deletions
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)
     }
 }