2020-04-06 06:42:21 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2023-10-19 12:19:10 +02:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2020-04-06 06:42:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (o *ObjectRoot) AppendEvent(event eventstore.Event) {
|
2020-04-21 17:00:32 +02:00
|
|
|
if o.AggregateID == "" {
|
2023-10-19 12:19:10 +02:00
|
|
|
o.AggregateID = event.Aggregate().ID
|
|
|
|
} else if o.AggregateID != event.Aggregate().ID {
|
2020-12-21 18:42:34 +01:00
|
|
|
return
|
2020-04-06 06:42:21 +02:00
|
|
|
}
|
2020-11-19 16:23:48 +01:00
|
|
|
if o.ResourceOwner == "" {
|
2023-10-19 12:19:10 +02:00
|
|
|
o.ResourceOwner = event.Aggregate().ResourceOwner
|
2020-11-19 16:23:48 +01:00
|
|
|
}
|
2022-03-23 09:02:39 +01:00
|
|
|
if o.InstanceID == "" {
|
2023-10-19 12:19:10 +02:00
|
|
|
o.InstanceID = event.Aggregate().InstanceID
|
2022-03-15 07:19:02 +01:00
|
|
|
}
|
2020-04-06 06:42:21 +02:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
o.ChangeDate = event.CreatedAt()
|
2020-12-14 17:24:01 +01:00
|
|
|
if o.CreationDate.IsZero() {
|
2020-04-06 06:42:21 +02:00
|
|
|
o.CreationDate = o.ChangeDate
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
o.Sequence = event.Sequence()
|
2020-04-06 06:42:21 +02:00
|
|
|
}
|
2020-05-11 10:16:27 +02:00
|
|
|
func (o *ObjectRoot) IsZero() bool {
|
|
|
|
return o.AggregateID == ""
|
|
|
|
}
|