feat(infra): transactional outbox — OutboxWriter port, PgOutboxWriter, OutboxRelay, TestOutbox; update create_thought + delete_thought

This commit is contained in:
2026-05-15 18:31:57 +02:00
parent 15b1d0fdb7
commit 6024a65060
16 changed files with 245 additions and 20 deletions

View File

@@ -44,6 +44,11 @@ pub trait EventConsumer: Send + Sync {
fn consume(&self) -> futures::stream::BoxStream<'_, Result<EventEnvelope, DomainError>>;
}
#[async_trait]
pub trait OutboxWriter: Send + Sync {
async fn append(&self, event: &DomainEvent) -> Result<(), DomainError>;
}
#[async_trait]
pub trait UserReader: Send + Sync {
async fn find_by_id(&self, id: &UserId) -> Result<Option<User>, DomainError>;

View File

@@ -937,6 +937,33 @@ impl EventPublisher for NoOpEventPublisher {
}
}
#[derive(Default, Clone)]
pub struct TestOutbox {
pub entries: Arc<Mutex<Vec<DomainEvent>>>,
}
impl TestOutbox {
pub fn staged(&self) -> Vec<DomainEvent> {
self.entries.lock().unwrap().clone()
}
}
#[async_trait]
impl OutboxWriter for TestOutbox {
async fn append(&self, event: &DomainEvent) -> Result<(), DomainError> {
self.entries.lock().unwrap().push(event.clone());
Ok(())
}
}
pub struct NoOpOutboxWriter;
#[async_trait]
impl OutboxWriter for NoOpOutboxWriter {
async fn append(&self, _e: &DomainEvent) -> Result<(), DomainError> {
Ok(())
}
}
#[cfg(test)]
mod ap_repo_tests {
use super::*;