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