Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding public view of events #95

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion integrationos-api/src/endpoints/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ pub fn get_router() -> Router<Arc<AppState>> {
#[derive(Serialize, Deserialize)]
pub struct CreateEventRequest;

impl PublicExt<Event> for CreateEventRequest {}
impl PublicExt<Event> 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;

Expand Down
1 change: 1 addition & 0 deletions integrationos-api/src/endpoints/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down
50 changes: 50 additions & 0 deletions integrationos-domain/src/domain/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Utc>,
pub arrived_date: DateTime<Utc>,
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<Duplicates>,
#[serde(flatten, default)]
pub record_metadata: RecordMetadata,
}

struct IntermediateEventFields<'a> {
access_key: &'a AccessKey,
encrypted_access_key: &'a EncryptedAccessKey<'a>,
Expand Down Expand Up @@ -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)]
Expand Down
Loading