Skip to content

Commit

Permalink
Add Reason to EventMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
emacsway committed Dec 19, 2023
1 parent 8d2c0d8 commit 0b6985e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion grade/internal/domain/seedwork/aggregate/event_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ func NewEventMeta(
// i.e. the time of obtaining the vector clock.
// Therefore, it is the same for all aggregate events at the time of saving.
occurredAt time.Time,
reason string,
) (EventMeta, error) {
return EventMeta{
eventId: eventId,
causationId: causationId,
correlationId: correlationId,
causalDependencies: causalDependencies,
occurredAt: occurredAt,
reason: reason,
}, nil
}

Expand All @@ -33,6 +35,7 @@ type EventMeta struct {
correlationId uuid.Uuid // CommandId
causalDependencies []CausalDependency
occurredAt time.Time
reason string
}

func (m EventMeta) EventId() uuid.Uuid {
Expand All @@ -55,6 +58,10 @@ func (m EventMeta) OccurredAt() time.Time {
return m.occurredAt
}

func (m EventMeta) Reason() string {
return m.reason
}

func (m EventMeta) Spawn(eventId uuid.Uuid) EventMeta {
n := m
n.eventId = eventId
Expand All @@ -77,6 +84,7 @@ type EventMetaExporterSetter interface {
SetCorrelationId(uuid.Uuid)
AddCausalDependency(CausalDependency)
SetOccurredAt(time.Time)
SetReason(string)
}

type EventMetaExporter struct {
Expand All @@ -85,6 +93,7 @@ type EventMetaExporter struct {
CorrelationId uuid.Uuid
CausalDependencies []CausalDependencyExporter
OccurredAt time.Time
Reason string
}

func (ex *EventMetaExporter) SetEventId(val uuid.Uuid) {
Expand All @@ -109,12 +118,17 @@ func (ex *EventMetaExporter) SetOccurredAt(val time.Time) {
ex.OccurredAt = val
}

func (ex *EventMetaExporter) SetReason(val string) {
ex.Reason = val
}

type EventMetaReconstitutor struct {
EventId uuid.Uuid
CausationId uuid.Uuid
CorrelationId uuid.Uuid
CausalDependencies []CausalDependencyReconstitutor
OccurredAt time.Time
Reason string
}

func (r EventMetaReconstitutor) Reconstitute() (EventMeta, error) {
Expand All @@ -126,5 +140,5 @@ func (r EventMetaReconstitutor) Reconstitute() (EventMeta, error) {
}
causalDependencies = append(causalDependencies, causalDependency)
}
return NewEventMeta(r.EventId, r.CausationId, r.CorrelationId, causalDependencies, r.OccurredAt)
return NewEventMeta(r.EventId, r.CausationId, r.CorrelationId, causalDependencies, r.OccurredAt, r.Reason)
}

0 comments on commit 0b6985e

Please sign in to comment.