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, Default, 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 pub event_type_prefix: Option<String>,
58
59 pub payload_filter: Option<String>,
62}
63
64#[derive(Debug, Serialize)]
66pub struct QueryEventsResponse {
67 pub events: Vec<EventDto>,
68 pub count: usize,
69 pub total_count: usize,
70 pub has_more: bool,
71}
72
73#[derive(Debug, Serialize, Deserialize, Clone)]
75pub struct EventDto {
76 pub id: Uuid,
77 pub event_type: String,
78 pub entity_id: String,
79 pub tenant_id: String,
80 pub payload: serde_json::Value,
81 pub timestamp: DateTime<Utc>,
82 pub metadata: Option<serde_json::Value>,
83 pub version: i64,
84}
85
86impl From<&Event> for EventDto {
87 fn from(event: &Event) -> Self {
88 Self {
89 id: event.id(),
90 event_type: event.event_type().to_string(),
91 entity_id: event.entity_id().to_string(),
92 tenant_id: event.tenant_id().to_string(),
93 payload: event.payload().clone(),
94 timestamp: event.timestamp(),
95 metadata: event.metadata().cloned(),
96 version: event.version(),
97 }
98 }
99}
100
101impl From<Event> for EventDto {
102 fn from(event: Event) -> Self {
103 EventDto::from(&event)
104 }
105}
106
107#[derive(Debug, Deserialize)]
109pub struct ListEntitiesRequest {
110 pub event_type_prefix: Option<String>,
112 pub payload_filter: Option<String>,
114 pub limit: Option<usize>,
116 pub offset: Option<usize>,
118}
119
120#[derive(Debug, Serialize)]
122pub struct EntitySummary {
123 pub entity_id: String,
124 pub event_count: usize,
125 pub last_event_type: String,
126 pub last_event_at: DateTime<Utc>,
127}
128
129#[derive(Debug, Serialize)]
131pub struct ListEntitiesResponse {
132 pub entities: Vec<EntitySummary>,
133 pub total: usize,
134 pub has_more: bool,
135}
136
137#[derive(Debug, Deserialize)]
139pub struct DetectDuplicatesRequest {
140 pub event_type_prefix: String,
142 pub group_by: String,
144 pub limit: Option<usize>,
146 pub offset: Option<usize>,
148}
149
150#[derive(Debug, Serialize)]
152pub struct DuplicateGroup {
153 pub key: serde_json::Value,
155 pub entity_ids: Vec<String>,
157 pub count: usize,
159}
160
161#[derive(Debug, Serialize)]
163pub struct DetectDuplicatesResponse {
164 pub duplicates: Vec<DuplicateGroup>,
166 pub total: usize,
168 pub has_more: bool,
170}
171
172#[derive(Debug, Deserialize)]
174pub struct IngestEventsBatchRequest {
175 pub events: Vec<IngestEventRequest>,
176}
177
178#[derive(Debug, Serialize)]
180pub struct IngestEventsBatchResponse {
181 pub total: usize,
183 pub ingested: usize,
185 pub events: Vec<IngestEventResponse>,
187}