lab_resource_manager/domain/ports/
notifier.rs

1// NOTE: これ以上肥大化するようであればnotifierディレクトリを作成してその中に適宜分割する
2use crate::domain::{
3    aggregates::resource_usage::entity::ResourceUsage, errors::DomainError, ports::PortError,
4};
5use async_trait::async_trait;
6use std::fmt;
7
8#[derive(Debug, Clone)]
9pub enum NotificationEvent {
10    ResourceUsageCreated(ResourceUsage),
11    ResourceUsageUpdated(ResourceUsage),
12    ResourceUsageDeleted(ResourceUsage),
13}
14
15#[async_trait]
16pub trait Notifier: Send + Sync {
17    async fn notify(&self, event: NotificationEvent) -> Result<(), NotificationError>;
18}
19
20#[derive(Debug)]
21pub enum NotificationError {
22    /// 通知送信の失敗
23    SendFailure(String),
24    /// リポジトリエラー(IdentityLink取得失敗等)
25    RepositoryError(String),
26}
27
28impl fmt::Display for NotificationError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            NotificationError::SendFailure(msg) => write!(f, "通知送信エラー: {}", msg),
32            NotificationError::RepositoryError(msg) => {
33                write!(f, "通知準備中のリポジトリエラー: {}", msg)
34            }
35        }
36    }
37}
38
39impl std::error::Error for NotificationError {}
40impl DomainError for NotificationError {}
41impl PortError for NotificationError {}