Skip to content

Commit

Permalink
add more efficient lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
n1nj4t4nuk1 committed Dec 3, 2024
1 parent 34d2bc8 commit 5e19c24
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions libs/cti/src/cves/application/create_one/cve_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ impl<R: CveRepository, E: EventBus> CryptoKeyCreator<R, E> {
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(())
Expand Down
14 changes: 7 additions & 7 deletions libs/cti/src/cves/domain/entities/cve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
16 changes: 8 additions & 8 deletions libs/cti/src/cves/domain/events/cve_created_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ 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,

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,
Expand All @@ -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,
Expand All @@ -37,16 +37,16 @@ impl CveCreatedEvent {
}
}

impl DomainEvent for CveCreatedEvent {
impl<'a> DomainEvent for CveCreatedEvent<'a> {
fn event_type(&self) -> String {
"[email protected]".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(),
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/events/src/domain/event_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ use super::domain_event::DomainEvent;

#[async_trait]
pub trait EventBus: Send + Sync + 'static {
async fn publish(&self, event: Arc<dyn DomainEvent>);
async fn publish<'a>(&self, event: Arc<dyn DomainEvent + 'a>);
}

0 comments on commit 5e19c24

Please sign in to comment.