pub mod attribute;
pub mod attribute_value;
pub mod brand;
pub mod item;
pub mod item_group;
pub mod item_variant;
pub mod uom;
pub mod uom_conversion;
pub mod attribute_type;
pub mod item_type;
pub mod catalog_status;
pub mod uom_type;
pub use attribute::Attribute;
pub use attribute::AttributeBuilder;
pub use attribute::AttributeId;
pub use attribute_value::AttributeValue;
pub use attribute_value::AttributeValueBuilder;
pub use attribute_value::AttributeValueId;
pub use brand::Brand;
pub use brand::BrandBuilder;
pub use brand::BrandId;
pub use item::Item;
pub use item::ItemBuilder;
pub use item::ItemId;
pub use item_group::ItemGroup;
pub use item_group::ItemGroupBuilder;
pub use item_group::ItemGroupId;
pub use item_variant::ItemVariant;
pub use item_variant::ItemVariantBuilder;
pub use item_variant::ItemVariantId;
pub use uom::Uom;
pub use uom::UomBuilder;
pub use uom::UomId;
pub use uom_conversion::UomConversion;
pub use uom_conversion::UomConversionBuilder;
pub use uom_conversion::UomConversionId;
pub use attribute_type::AttributeType;
pub use item_type::ItemType;
pub use catalog_status::CatalogStatus;
pub use uom_type::UomType;
use std::fmt::Debug;
pub trait Entity: Debug + Clone {
type Id: Debug + Clone + PartialEq;
fn entity_id(&self) -> &Self::Id;
fn entity_type() -> &'static str;
}
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
pub struct AuditMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_by: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_by: Option<Uuid>,
}
impl AuditMetadata {
pub fn new() -> Self {
Self {
created_at: Some(Utc::now()),
..Default::default()
}
}
pub fn with_creator(creator_id: Uuid) -> Self {
Self {
created_at: Some(Utc::now()),
created_by: Some(creator_id),
..Default::default()
}
}
pub fn touch(&mut self) {
self.updated_at = Some(Utc::now());
}
pub fn touch_by(&mut self, updater_id: Uuid) {
self.updated_at = Some(Utc::now());
self.updated_by = Some(updater_id);
}
pub fn soft_delete(&mut self) {
self.deleted_at = Some(Utc::now());
}
pub fn soft_delete_by(&mut self, deleter_id: Uuid) {
self.deleted_at = Some(Utc::now());
self.deleted_by = Some(deleter_id);
}
pub fn restore(&mut self) {
self.deleted_at = None;
self.deleted_by = None;
}
pub fn is_deleted(&self) -> bool {
self.deleted_at.is_some()
}
pub fn is_active(&self) -> bool {
self.deleted_at.is_none()
}
}