fix domain ports: add EventConsumer, use ID newtypes

This commit is contained in:
2026-07-12 01:27:38 +02:00
parent 0166e829c1
commit 6d12ac4c5e
4 changed files with 12 additions and 7 deletions

View File

@@ -3,10 +3,10 @@
//! Records user and system actions for the admin dashboard's activity feed. //! Records user and system actions for the admin dashboard's activity feed.
use async_trait::async_trait; use async_trait::async_trait;
use uuid::Uuid;
use crate::errors::DomainResult; use crate::errors::DomainResult;
use crate::models::ActivityEvent; use crate::models::ActivityEvent;
use crate::value_objects::ChannelId;
/// Port for activity log persistence. /// Port for activity log persistence.
#[async_trait] #[async_trait]
@@ -16,7 +16,7 @@ pub trait ActivityLogCommand: Send + Sync {
&self, &self,
event_type: &str, event_type: &str,
detail: &str, detail: &str,
channel_id: Option<Uuid>, channel_id: Option<ChannelId>,
) -> DomainResult<()>; ) -> DomainResult<()>;
} }

View File

@@ -42,6 +42,13 @@ pub trait EventPublisher: Send + Sync {
async fn publish(&self, event: DomainEvent) -> DomainResult<()>; async fn publish(&self, event: DomainEvent) -> DomainResult<()>;
} }
/// Port for consuming domain events from a queue or channel.
#[async_trait]
pub trait EventConsumer: Send + Sync {
/// Block until the next event is available and return it.
async fn recv(&self) -> DomainResult<DomainEvent>;
}
/// Port for handling domain events. /// Port for handling domain events.
/// ///
/// Each handler is responsible for one side-effect (e.g. logging, webhook /// Each handler is responsible for one side-effect (e.g. logging, webhook

View File

@@ -25,7 +25,7 @@ pub mod user;
pub use activity::{ActivityLogCommand, ActivityLogQuery}; pub use activity::{ActivityLogCommand, ActivityLogQuery};
pub use auth::AuthService; pub use auth::AuthService;
pub use channel::{ChannelCommand, ChannelQuery}; pub use channel::{ChannelCommand, ChannelQuery};
pub use events::{DomainEvent, EventHandler, EventPublisher}; pub use events::{DomainEvent, EventConsumer, EventHandler, EventPublisher};
pub use library::{LibraryCommand, LibraryQuery, LibrarySyncAdapter}; pub use library::{LibraryCommand, LibraryQuery, LibrarySyncAdapter};
pub use media::{ pub use media::{
Collection, IMediaProvider, IProviderRegistry, ProviderCapabilities, SeriesSummary, Collection, IMediaProvider, IProviderRegistry, ProviderCapabilities, SeriesSummary,

View File

@@ -4,11 +4,9 @@ use std::collections::HashMap;
use async_trait::async_trait; use async_trait::async_trait;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use uuid::Uuid;
use crate::errors::DomainResult; use crate::errors::DomainResult;
use crate::models::{GeneratedSchedule, PlaybackRecord}; use crate::models::{GeneratedSchedule, PlaybackRecord};
use crate::value_objects::{BlockId, ChannelId, MediaItemId}; use crate::value_objects::{BlockId, ChannelId, MediaItemId, ScheduleId};
/// Write-side port for schedule and playback persistence. /// Write-side port for schedule and playback persistence.
#[async_trait] #[async_trait]
@@ -71,6 +69,6 @@ pub trait ScheduleQuery: Send + Sync {
async fn get_schedule_by_id( async fn get_schedule_by_id(
&self, &self,
channel_id: ChannelId, channel_id: ChannelId,
schedule_id: Uuid, schedule_id: ScheduleId,
) -> DomainResult<Option<GeneratedSchedule>>; ) -> DomainResult<Option<GeneratedSchedule>>;
} }