allsource_core/application/dto/
event_dto.rs1use crate::domain::entities::Event;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Debug, Deserialize)]
8pub struct IngestEventRequest {
9 pub event_type: String,
10 pub entity_id: String,
11 pub tenant_id: Option<String>, pub payload: serde_json::Value,
13 pub metadata: Option<serde_json::Value>,
14}
15
16#[derive(Debug, Serialize)]
18pub struct IngestEventResponse {
19 pub event_id: Uuid,
20 pub timestamp: DateTime<Utc>,
21}
22
23impl IngestEventResponse {
24 pub fn from_event(event: &Event) -> Self {
25 Self {
26 event_id: event.id(),
27 timestamp: event.timestamp(),
28 }
29 }
30}
31
32#[derive(Debug, Deserialize)]
34pub struct QueryEventsRequest {
35 pub entity_id: Option<String>,
37
38 pub event_type: Option<String>,
40
41 pub tenant_id: Option<String>,
43
44 pub as_of: Option<DateTime<Utc>>,
46
47 pub since: Option<DateTime<Utc>>,
49
50 pub until: Option<DateTime<Utc>>,
52
53 pub limit: Option<usize>,
55}
56
57#[derive(Debug, Serialize)]
59pub struct QueryEventsResponse {
60 pub events: Vec<EventDto>,
61 pub count: usize,
62}
63
64#[derive(Debug, Serialize, Clone)]
66pub struct EventDto {
67 pub id: Uuid,
68 pub event_type: String,
69 pub entity_id: String,
70 pub tenant_id: String,
71 pub payload: serde_json::Value,
72 pub timestamp: DateTime<Utc>,
73 pub metadata: Option<serde_json::Value>,
74 pub version: i64,
75}
76
77impl From<&Event> for EventDto {
78 fn from(event: &Event) -> Self {
79 Self {
80 id: event.id(),
81 event_type: event.event_type().to_string(),
82 entity_id: event.entity_id().to_string(),
83 tenant_id: event.tenant_id().to_string(),
84 payload: event.payload().clone(),
85 timestamp: event.timestamp(),
86 metadata: event.metadata().cloned(),
87 version: event.version(),
88 }
89 }
90}
91
92impl From<Event> for EventDto {
93 fn from(event: Event) -> Self {
94 EventDto::from(&event)
95 }
96}