acts_next/store/data/
event.rs1use crate::{
2 Act, ActError, Result,
3 store::{DbCollectionIden, StoreIden},
4 utils,
5};
6use serde::{Deserialize, Serialize};
7
8#[derive(Default, Deserialize, Serialize, Debug, Clone)]
9pub struct Event {
10 pub id: String,
11 pub name: String,
12 pub mid: String,
13 pub ver: i32,
14
15 pub uses: String,
16 pub params: String,
17
18 pub create_time: i64,
19 pub timestamp: i64,
20}
21
22impl DbCollectionIden for Event {
23 fn iden() -> StoreIden {
24 StoreIden::Events
25 }
26}
27
28impl Event {
29 pub fn from_act(act: &Act, mid: &str, ver: i32, event_id: &str) -> Result<Self> {
30 Ok(Self {
31 id: event_id.to_string(),
32 name: act.name.to_string(),
33 mid: mid.to_string(),
34 ver,
35 uses: act.uses.clone(),
36 params: serde_json::to_string(&act.params).map_err(|err| {
37 ActError::Convert(format!("failed to convert params to string: {}", err))
38 })?,
39 create_time: utils::time::time_millis(),
40 timestamp: utils::time::timestamp(),
41 })
42 }
43}
44
45#[cfg(test)]
46mod tests {}