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/unit.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/unit.rs')
| -rw-r--r-- | crates/rocie-server/src/storage/sql/unit.rs | 31 |
1 files changed, 26 insertions, 5 deletions
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) } } |
