diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-23 08:33:06 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-23 08:34:45 +0200 |
| commit | 2dc74d621399be454abbbff892fb46204ddc6e7b (patch) | |
| tree | f9525527fc09c465d4e2e4a4f665bfd444b889f8 /crates/rocie-server/src/storage/sql/barcode.rs | |
| parent | feat: Provide basic barcode handling support (diff) | |
| download | server-2dc74d621399be454abbbff892fb46204ddc6e7b.zip | |
feat(treewide): Add tests and barcode buying/consuming
Diffstat (limited to 'crates/rocie-server/src/storage/sql/barcode.rs')
| -rw-r--r-- | crates/rocie-server/src/storage/sql/barcode.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/rocie-server/src/storage/sql/barcode.rs b/crates/rocie-server/src/storage/sql/barcode.rs new file mode 100644 index 0000000..239ed8c --- /dev/null +++ b/crates/rocie-server/src/storage/sql/barcode.rs @@ -0,0 +1,30 @@ +use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; + +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); + +impl BarcodeId { + pub(crate) fn to_db(self) -> i64 { + i64::from(self.0) + } + pub(crate) fn from_db(val: i64) -> Self { + Self(u32::try_from(val).expect("Should be strictly positive")) + } +} + +#[derive(ToSchema, Debug, Clone, Copy, Serialize, Deserialize)] +pub(crate) struct UnitAmount { + #[schema(format = Int64, minimum = 0)] + pub(crate) value: u32, + pub(crate) unit: UnitId, +} |
