feat: event store — persist domain events to Postgres event_log table via composite publisher

This commit is contained in:
2026-05-31 18:36:10 +02:00
parent d022cb9068
commit aa09aec66b
10 changed files with 143 additions and 10 deletions

View File

@@ -0,0 +1,26 @@
use async_trait::async_trait;
use domain::{
errors::DomainError,
events::DomainEvent,
ports::{EventPublisher, EventStore},
};
use std::sync::Arc;
pub struct CompositeEventPublisher {
primary: Arc<dyn EventPublisher>,
store: Arc<dyn EventStore>,
}
impl CompositeEventPublisher {
pub fn new(primary: Arc<dyn EventPublisher>, store: Arc<dyn EventStore>) -> Self {
Self { primary, store }
}
}
#[async_trait]
impl EventPublisher for CompositeEventPublisher {
async fn publish(&self, event: &DomainEvent) -> Result<(), DomainError> {
self.store.append(event).await?;
self.primary.publish(event).await
}
}

View File

@@ -1,3 +1,6 @@
pub mod composite;
pub use composite::CompositeEventPublisher;
use async_trait::async_trait;
use domain::{
errors::DomainError,