diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-23 17:16:23 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-23 17:16:23 +0200 |
| commit | e536cb326a67fffd511ead4a87655ca5ef98bf29 (patch) | |
| tree | 96deb4e27b25c1e82a5d8b2be01aed650521bfc7 /crates/rocie-server/src/storage/sql/barcode.rs | |
| parent | chore(crates/rocies-client): Regenerate (diff) | |
| download | server-e536cb326a67fffd511ead4a87655ca5ef98bf29.zip | |
feat(crates/rocies-server): Don't make the newtype wrappers transparent in the openapi spec
This makes using the generated code significantly easier and type safer.
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, 25 insertions, 5 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, } |
