1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use async_trait::async_trait;

use chrono::{DateTime, Utc};

use uuid::Uuid;

use crate::domain::Message;

#[async_trait]
pub trait OutBox: Send + Sync + 'static {
    fn convert_event(&self) -> Box<dyn Message>;
    fn tag_processed(&mut self);

    fn id(&self) -> Uuid;
    fn aggregate_id(&self) -> &str;
    fn topic(&self) -> &str;
    fn state(&self) -> &str;
    fn processed(&self) -> bool;
    fn create_dt(&self) -> DateTime<Utc>;
}

#[macro_export]
macro_rules! convert_event {
    ( $obj:expr, $( $type: ty ), * ) => {
        match $obj.topic.as_str() {
          $(stringify!($type)=> serde_json::from_str::<$type>($obj.state.as_str()).expect("Given type not deserializable!").message_clone() ,)*
          _ => {
                panic!("Such event not allowed to process through outbox.");
          }
        }
    };
}