pub struct Metadata {
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub deleted_at: Option<DateTime<Utc>>,
pub created_by: Option<Uuid>,
pub updated_by: Option<Uuid>,
pub deleted_by: Option<Uuid>,
}Fields§
§created_at: DateTime<Utc>When the record was created
updated_at: DateTime<Utc>When the record was last updated
deleted_at: Option<DateTime<Utc>>When the record was soft deleted (if applicable)
created_by: Option<Uuid>ID of user who created the record
updated_by: Option<Uuid>ID of user who last updated the record
deleted_by: Option<Uuid>ID of user who soft deleted the record
Implementations§
Source§impl Metadata
impl Metadata
Sourcepub fn new(
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
deleted_at: Option<DateTime<Utc>>,
created_by: Option<Uuid>,
updated_by: Option<Uuid>,
deleted_by: Option<Uuid>,
) -> Self
pub fn new( created_at: DateTime<Utc>, updated_at: DateTime<Utc>, deleted_at: Option<DateTime<Utc>>, created_by: Option<Uuid>, updated_by: Option<Uuid>, deleted_by: Option<Uuid>, ) -> Self
Create a new Metadata value object
Sourcepub fn new_record(created_by: Option<Uuid>) -> Self
pub fn new_record(created_by: Option<Uuid>) -> Self
Create metadata for a new record (created now)
Sourcepub fn mark_updated(&mut self, updated_by: Option<Uuid>)
pub fn mark_updated(&mut self, updated_by: Option<Uuid>)
NOTE: These methods use &mut self for domain state transitions. While value objects are typically immutable, audit metadata represents a special case where the metadata tracks the lifecycle state of an entity.
Mark the record as updated
Updates the updated_at timestamp and sets the updated_by user. This is a domain state transition that occurs when an entity is modified.
Sourcepub fn mark_deleted(&mut self, deleted_by: Option<Uuid>)
pub fn mark_deleted(&mut self, deleted_by: Option<Uuid>)
Mark the record as soft deleted
Sets the deleted_at timestamp and deleted_by user. This is a domain state transition that occurs when an entity is soft deleted.
Sourcepub fn is_deleted(&self) -> bool
pub fn is_deleted(&self) -> bool
Check if the record is soft deleted
Sourcepub fn builder() -> MetadataBuilder
pub fn builder() -> MetadataBuilder
Create a builder for Metadata
Sourcepub fn to_json_value(&self) -> Result<Value, Error>
pub fn to_json_value(&self) -> Result<Value, Error>
Convert to serde_json::Value for storage
Sourcepub fn from_json_value(value: Value) -> Result<Self, Error>
pub fn from_json_value(value: Value) -> Result<Self, Error>
Convert from serde_json::Value from storage
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Metadata
impl<'de> Deserialize<'de> for Metadata
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Metadata
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnsafeUnpin for Metadata
impl UnwindSafe for Metadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more