2020-04-06 04:42:21 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ObjectRoot struct {
|
2020-05-11 10:16:29 +00:00
|
|
|
AggregateID string `json:"-"`
|
|
|
|
Sequence uint64 `json:"-"`
|
|
|
|
ResourceOwner string `json:"-"`
|
2022-03-23 08:02:39 +00:00
|
|
|
InstanceID string `json:"-"`
|
2020-05-11 10:16:29 +00:00
|
|
|
CreationDate time.Time `json:"-"`
|
|
|
|
ChangeDate time.Time `json:"-"`
|
2020-04-06 04:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (o *ObjectRoot) AppendEvent(event *Event) {
|
2020-04-21 15:00:32 +00:00
|
|
|
if o.AggregateID == "" {
|
|
|
|
o.AggregateID = event.AggregateID
|
2020-12-21 17:42:34 +00:00
|
|
|
} else if o.AggregateID != event.AggregateID {
|
|
|
|
return
|
2020-04-06 04:42:21 +00:00
|
|
|
}
|
2020-11-19 15:23:48 +00:00
|
|
|
if o.ResourceOwner == "" {
|
|
|
|
o.ResourceOwner = event.ResourceOwner
|
|
|
|
}
|
2022-03-23 08:02:39 +00:00
|
|
|
if o.InstanceID == "" {
|
|
|
|
o.InstanceID = event.InstanceID
|
2022-03-15 06:19:02 +00:00
|
|
|
}
|
2020-04-06 04:42:21 +00:00
|
|
|
|
|
|
|
o.ChangeDate = event.CreationDate
|
2020-12-14 16:24:01 +00:00
|
|
|
if o.CreationDate.IsZero() {
|
2020-04-06 04:42:21 +00:00
|
|
|
o.CreationDate = o.ChangeDate
|
|
|
|
}
|
|
|
|
|
|
|
|
o.Sequence = event.Sequence
|
|
|
|
}
|
2020-05-11 08:16:27 +00:00
|
|
|
func (o *ObjectRoot) IsZero() bool {
|
|
|
|
return o.AggregateID == ""
|
|
|
|
}
|