Skip to content

Refactor C8yCreateEvent struct #2429

Open
@rina23q

Description

@rina23q

Is your refactoring request related to a problem? Please describe.
This request is originated by #2421 (comment)

the need to create a different representations with externalSource for JSON over MQTT and source for HTTP. We should only be needing just one struct where that source field can be an enum of either externalSource or source. If this isn't trivial, you may address that refactoring in a different PR.


C8yCreateEvent is used for both cases, creating an event via JSON over MQTT and HTTP.
For HTTP, source holds the internal ID of a device, and for MQTT, extras holds the external ID of a device as externalSource.

The current implementation is not clear what the caller of the API needs to provide to the struct.

pub struct C8yCreateEvent {
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<C8yManagedObject>,
#[serde(rename = "type")]
pub event_type: String,
#[serde(with = "time::serde::rfc3339")]
pub time: OffsetDateTime,
pub text: String,
#[serde(flatten)]
pub extras: HashMap<String, Value>,
}

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions