2020-11-06 21:09:19 +00:00
|
|
|
package eventstore
|
|
|
|
|
2020-11-11 16:51:44 +00:00
|
|
|
func NewAggregate(
|
|
|
|
id string,
|
|
|
|
typ AggregateType,
|
|
|
|
resourceOwner string,
|
|
|
|
version Version,
|
|
|
|
previousSequence uint64,
|
|
|
|
) *Aggregate {
|
2020-11-06 21:09:19 +00:00
|
|
|
return &Aggregate{
|
2020-11-11 16:51:44 +00:00
|
|
|
id: id,
|
|
|
|
typ: typ,
|
|
|
|
resourceOwner: resourceOwner,
|
|
|
|
version: version,
|
|
|
|
previousSequence: previousSequence,
|
|
|
|
events: []EventPusher{},
|
2020-11-06 21:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-11 16:51:44 +00:00
|
|
|
//Aggregate is the basic implementation of aggregater
|
2020-11-06 21:09:19 +00:00
|
|
|
type Aggregate struct {
|
2020-11-11 16:51:44 +00:00
|
|
|
id string `json:"-"`
|
|
|
|
typ AggregateType `json:"-"`
|
|
|
|
events []EventPusher `json:"-"`
|
|
|
|
resourceOwner string `json:"-"`
|
|
|
|
version Version `json:"-"`
|
|
|
|
previousSequence uint64 `json:"-"`
|
2020-11-06 21:09:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 16:51:44 +00:00
|
|
|
//PushEvents adds all the events to the aggregate.
|
|
|
|
// The added events will be pushed to eventstore
|
|
|
|
func (a *Aggregate) PushEvents(events ...EventPusher) *Aggregate {
|
|
|
|
a.events = append(a.events, events...)
|
2020-11-06 21:09:19 +00:00
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2020-11-11 16:51:44 +00:00
|
|
|
//ID implements aggregater
|
|
|
|
func (a *Aggregate) ID() string {
|
|
|
|
return a.id
|
|
|
|
}
|
|
|
|
|
|
|
|
//Type implements aggregater
|
|
|
|
func (a *Aggregate) Type() AggregateType {
|
|
|
|
return a.typ
|
|
|
|
}
|
|
|
|
|
|
|
|
//Events implements aggregater
|
|
|
|
func (a *Aggregate) Events() []EventPusher {
|
|
|
|
return a.events
|
|
|
|
}
|
|
|
|
|
|
|
|
//ResourceOwner implements aggregater
|
|
|
|
func (a *Aggregate) ResourceOwner() string {
|
|
|
|
return a.resourceOwner
|
|
|
|
}
|
|
|
|
|
|
|
|
//Version implements aggregater
|
|
|
|
func (a *Aggregate) Version() Version {
|
|
|
|
return a.version
|
|
|
|
}
|
2020-11-06 21:09:19 +00:00
|
|
|
|
2020-11-11 16:51:44 +00:00
|
|
|
//PreviousSequence implements aggregater
|
|
|
|
func (a *Aggregate) PreviousSequence() uint64 {
|
|
|
|
return a.previousSequence
|
2020-11-06 21:09:19 +00:00
|
|
|
}
|