diff --git a/libs/cti/src/cves/application/create_one/cve_creator.rs b/libs/cti/src/cves/application/create_one/cve_creator.rs index 6100d6f..64596f9 100644 --- a/libs/cti/src/cves/application/create_one/cve_creator.rs +++ b/libs/cti/src/cves/application/create_one/cve_creator.rs @@ -17,21 +17,21 @@ impl CryptoKeyCreator { CryptoKeyCreator { repository: cve_repository, event_bus } } - pub async fn run( - &self, - id: CveId, + pub async fn run<'a>( + &'a self, + id: &'a CveId, state: CveState, date_published: CvePublicationDate, description: CveDescription, ) -> Result<(), DomainError> { debug!("Starting CVE creation"); - let key = Cve::new(id.clone(), state.clone(), date_published.clone(), description.clone()); + let key = Cve::new(&id, state.clone(), date_published.clone(), description.clone()); let res = self.repository.create_one(&key).await; if res.is_err() { debug!("Error creating CVE with id: {}", id.value()); return Err(res.err().unwrap()); } - let created_event = CveCreatedEvent::new_shared(id.clone(), state, date_published, description); + let created_event = CveCreatedEvent::new_shared(&id, state, date_published, description); self.event_bus.publish(created_event).await; debug!("CVE with id: {} created", id.value()); Ok(()) diff --git a/libs/cti/src/cves/domain/entities/cve.rs b/libs/cti/src/cves/domain/entities/cve.rs index 108284b..aeffdeb 100644 --- a/libs/cti/src/cves/domain/entities/cve.rs +++ b/libs/cti/src/cves/domain/entities/cve.rs @@ -3,17 +3,17 @@ use aggregate_root::domain::aggregate_root::AggregateRoot; use super::{cve_description::CveDescription, cve_id::CveId, cve_publication_date::CvePublicationDate, cve_state::CveState}; -pub struct Cve { - pub id: CveId, +pub struct Cve<'a> { + pub id: &'a CveId, pub state: CveState, pub date_published: CvePublicationDate, pub description: CveDescription, } -impl Cve { +impl<'a> Cve<'a> { pub fn new( - id: CveId, + id: &'a CveId, state: CveState, date_published: CvePublicationDate, description: CveDescription @@ -27,16 +27,16 @@ impl Cve { } } -impl AggregateRoot for Cve { +impl<'a> AggregateRoot for Cve<'a> { fn get_type() -> String { "com.tanukibox.tanuki-library.cti.cve".to_string() } } -impl Clone for Cve { +impl<'a> Clone for Cve<'a> { fn clone(&self) -> Self { Self::new( - self.id.clone(), + self.id, self.state.clone(), self.date_published.clone(), self.description.clone(), diff --git a/libs/cti/src/cves/domain/events/cve_created_event.rs b/libs/cti/src/cves/domain/events/cve_created_event.rs index 4ced2fe..3228991 100644 --- a/libs/cti/src/cves/domain/events/cve_created_event.rs +++ b/libs/cti/src/cves/domain/events/cve_created_event.rs @@ -4,10 +4,10 @@ use events::domain::domain_event::DomainEvent; use crate::cves::domain::entities::{cve_description::CveDescription, cve_id::CveId, cve_publication_date::CvePublicationDate, cve_state::CveState}; -pub struct CveCreatedEvent { +pub struct CveCreatedEvent<'a> { pub id: String, - pub cve_id: CveId, + pub cve_id: &'a CveId, pub cve_state: CveState, pub cve_date_published: CvePublicationDate, pub cve_description: CveDescription, @@ -15,9 +15,9 @@ pub struct CveCreatedEvent { pub occurred_on: String, } -impl CveCreatedEvent { +impl<'a> CveCreatedEvent<'a> { pub fn new( - cve_id: CveId, + cve_id: &'a CveId, cve_state: CveState, cve_date_published: CvePublicationDate, cve_description: CveDescription, @@ -28,7 +28,7 @@ impl CveCreatedEvent { } pub fn new_shared( - cve_id: CveId, + cve_id: &'a CveId, cve_state: CveState, cve_date_published: CvePublicationDate, cve_description: CveDescription, @@ -37,16 +37,16 @@ impl CveCreatedEvent { } } -impl DomainEvent for CveCreatedEvent { +impl<'a> DomainEvent for CveCreatedEvent<'a> { fn event_type(&self) -> String { "com.tanukibox.cti.cve.created@1.0.0".to_string() } } -impl Clone for CveCreatedEvent { +impl<'a> Clone for CveCreatedEvent<'a> { fn clone(&self) -> Self { let mut event = Self::new( - self.cve_id.clone(), + self.cve_id, self.cve_state.clone(), self.cve_date_published.clone(), self.cve_description.clone(), diff --git a/libs/shared/events/src/domain/event_bus.rs b/libs/shared/events/src/domain/event_bus.rs index daa2b3e..4ce2cd0 100644 --- a/libs/shared/events/src/domain/event_bus.rs +++ b/libs/shared/events/src/domain/event_bus.rs @@ -8,5 +8,5 @@ use super::domain_event::DomainEvent; #[async_trait] pub trait EventBus: Send + Sync + 'static { - async fn publish(&self, event: Arc); + async fn publish<'a>(&self, event: Arc); } \ No newline at end of file