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, }