From c3c44ff74946ce49a8d965edb92d8dede1bcbee6 Mon Sep 17 00:00:00 2001 From: Samuel Gomez Date: Sun, 21 Jul 2024 18:32:17 +0100 Subject: [PATCH] chore: adding public view of events --- integrationos-api/src/endpoints/events.rs | 6 ++- integrationos-api/src/endpoints/unified.rs | 1 + integrationos-domain/src/domain/event/mod.rs | 50 ++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/integrationos-api/src/endpoints/events.rs b/integrationos-api/src/endpoints/events.rs index f83ac1f1..a4115882 100644 --- a/integrationos-api/src/endpoints/events.rs +++ b/integrationos-api/src/endpoints/events.rs @@ -13,7 +13,11 @@ pub fn get_router() -> Router> { #[derive(Serialize, Deserialize)] pub struct CreateEventRequest; -impl PublicExt for CreateEventRequest {} +impl PublicExt for CreateEventRequest { + fn public(input: Event) -> serde_json::Value { + serde_json::to_value(input.to_public()).unwrap_or_default() + } +} impl RequestExt for CreateEventRequest { type Output = Event; diff --git a/integrationos-api/src/endpoints/unified.rs b/integrationos-api/src/endpoints/unified.rs index d90c8f6c..564644d7 100644 --- a/integrationos-api/src/endpoints/unified.rs +++ b/integrationos-api/src/endpoints/unified.rs @@ -284,6 +284,7 @@ pub async fn process_request( let mut metadata = body.get(META).unwrap_or(&response.metadata).clone(); if let Some(meta) = metadata.as_object_mut() { meta.insert("status_code".to_string(), json!(status_code)); + meta.insert("path".to_string(), json!("v1/unified")); }; let body = serde_json::to_string(&json!({ diff --git a/integrationos-domain/src/domain/event/mod.rs b/integrationos-domain/src/domain/event/mod.rs index 2b3ef3f8..956025c1 100644 --- a/integrationos-domain/src/domain/event/mod.rs +++ b/integrationos-domain/src/domain/event/mod.rs @@ -52,6 +52,34 @@ pub struct Event { pub record_metadata: RecordMetadata, } +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] +#[cfg_attr(feature = "dummy", derive(fake::Dummy))] +#[serde(rename_all = "camelCase")] +pub struct PublicEvent { + #[serde(rename = "_id")] + pub id: Id, + pub key: Id, + pub name: String, + pub r#type: String, + pub group: String, + pub topic: String, + pub environment: Environment, + pub body: String, + #[serde(with = "http_serde_ext::header_map")] + pub headers: HeaderMap, + #[serde(with = "chrono::serde::ts_milliseconds")] + pub arrived_at: DateTime, + pub arrived_date: DateTime, + pub state: EventState, + pub ownership: Ownership, + pub hashes: [HashValue; 3], + pub payload_byte_length: usize, + #[serde(skip_serializing_if = "Option::is_none", default)] + pub duplicates: Option, + #[serde(flatten, default)] + pub record_metadata: RecordMetadata, +} + struct IntermediateEventFields<'a> { access_key: &'a AccessKey, encrypted_access_key: &'a EncryptedAccessKey<'a>, @@ -136,6 +164,28 @@ impl Event { record_metadata: Default::default(), } } + + pub fn to_public(self) -> PublicEvent { + PublicEvent { + id: self.id, + key: self.key, + name: self.name.clone(), + r#type: self.r#type.clone(), + group: self.group.clone(), + topic: self.topic.clone(), + environment: self.environment, + body: self.body.clone(), + headers: self.headers.clone(), + arrived_at: self.arrived_at, + arrived_date: self.arrived_date, + state: self.state, + ownership: self.ownership.clone(), + hashes: self.hashes, + payload_byte_length: self.payload_byte_length, + duplicates: self.duplicates.clone(), + record_metadata: self.record_metadata.clone(), + } + } } #[cfg(test)]