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 pub expected_version: Option<u64>,
17}
18
19#[derive(Debug, Serialize)]
21pub struct IngestEventResponse {
22 pub event_id: Uuid,
23 pub timestamp: DateTime<Utc>,
24 #[serde(skip_serializing_if = "Option::is_none")]
26 pub version: Option<u64>,
27}
28
29impl IngestEventResponse {
30 pub fn from_event(event: &Event) -> Self {
31 Self {
32 event_id: event.id(),
33 timestamp: event.timestamp(),
34 version: None,
35 }
36 }
37}
38
39#[derive(Debug, Default, Deserialize)]
41pub struct QueryEventsRequest {
42 pub entity_id: Option<String>,
44
45 pub event_type: Option<String>,
47
48 pub tenant_id: Option<String>,
50
51 pub as_of: Option<DateTime<Utc>>,
53
54 pub since: Option<DateTime<Utc>>,
56
57 pub until: Option<DateTime<Utc>>,
59
60 pub limit: Option<usize>,
62
63 pub event_type_prefix: Option<String>,
65
66 pub payload_filter: Option<String>,
69}
70
71#[derive(Debug, Serialize)]
73pub struct QueryEventsResponse {
74 pub events: Vec<EventDto>,
75 pub count: usize,
76 pub total_count: usize,
77 pub has_more: bool,
78 #[serde(skip_serializing_if = "Option::is_none")]
80 pub entity_version: Option<u64>,
81}
82
83#[derive(Debug, Serialize, Deserialize, Clone)]
85pub struct EventDto {
86 pub id: Uuid,
87 pub event_type: String,
88 pub entity_id: String,
89 pub tenant_id: String,
90 pub payload: serde_json::Value,
91 pub timestamp: DateTime<Utc>,
92 pub metadata: Option<serde_json::Value>,
93 pub version: i64,
94}
95
96impl From<&Event> for EventDto {
97 fn from(event: &Event) -> Self {
98 Self {
99 id: event.id(),
100 event_type: event.event_type().to_string(),
101 entity_id: event.entity_id().to_string(),
102 tenant_id: event.tenant_id().to_string(),
103 payload: event.payload().clone(),
104 timestamp: event.timestamp(),
105 metadata: event.metadata().cloned(),
106 version: event.version(),
107 }
108 }
109}
110
111impl From<Event> for EventDto {
112 fn from(event: Event) -> Self {
113 EventDto::from(&event)
114 }
115}
116
117#[derive(Debug, Default, Deserialize)]
119pub struct ListEntitiesRequest {
120 pub event_type_prefix: Option<String>,
122 pub payload_filter: Option<String>,
124 pub limit: Option<usize>,
126 pub offset: Option<usize>,
128 pub order: Option<String>,
133}
134
135#[derive(Debug, Serialize)]
137pub struct EntitySummary {
138 pub entity_id: String,
139 pub event_count: usize,
140 pub last_event_type: String,
141 pub last_event_at: DateTime<Utc>,
142}
143
144#[derive(Debug, Serialize)]
146pub struct ListEntitiesResponse {
147 pub entities: Vec<EntitySummary>,
148 pub total: usize,
149 pub has_more: bool,
150}
151
152#[derive(Debug, Deserialize)]
154pub struct DetectDuplicatesRequest {
155 pub event_type_prefix: String,
157 pub group_by: String,
159 pub limit: Option<usize>,
161 pub offset: Option<usize>,
163}
164
165#[derive(Debug, Serialize)]
167pub struct DuplicateGroup {
168 pub key: serde_json::Value,
170 pub entity_ids: Vec<String>,
172 pub count: usize,
174}
175
176#[derive(Debug, Serialize)]
178pub struct DetectDuplicatesResponse {
179 pub duplicates: Vec<DuplicateGroup>,
181 pub total: usize,
183 pub has_more: bool,
185}
186
187#[derive(Debug, Deserialize)]
189pub struct IngestEventsBatchRequest {
190 pub events: Vec<IngestEventRequest>,
191}
192
193#[derive(Debug, Serialize)]
195pub struct IngestEventsBatchResponse {
196 pub total: usize,
198 pub ingested: usize,
200 pub events: Vec<IngestEventResponse>,
202}