mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
31ea9d1acd
* feat: user new eventstore * feat: rename query builder * feat: human events * feat: human events * feat: events * feat: phone events * feat: phone events * feat: profile, address events * feat: mfa, otp * feat: webauthn events * feat: webauthn events * feat: webauthn events * feat: enums * feat: new events * feat: user events * feat: domain events * feat: all v2 events * feat: all v1 events * feat: pkg structure * feat: change events * feat: better naming * feat: better naming
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package user
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
)
|
|
|
|
type ReadModel struct {
|
|
eventstore.ReadModel
|
|
}
|
|
|
|
func NewReadModel(id string) *ReadModel {
|
|
return &ReadModel{
|
|
ReadModel: eventstore.ReadModel{
|
|
AggregateID: id,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (rm *ReadModel) AppendEvents(events ...eventstore.EventReader) {
|
|
rm.ReadModel.AppendEvents(events...)
|
|
for _, event := range events {
|
|
switch event.(type) {
|
|
// TODO: implement append events
|
|
}
|
|
}
|
|
}
|
|
|
|
func (rm *ReadModel) Reduce() (err error) {
|
|
for _, event := range rm.Events {
|
|
switch event.(type) {
|
|
//TODO: implement reduce
|
|
}
|
|
}
|
|
for _, reduce := range []func() error{
|
|
rm.ReadModel.Reduce,
|
|
} {
|
|
if err = reduce(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (rm *ReadModel) AppendAndReduce(events ...eventstore.EventReader) error {
|
|
rm.AppendEvents(events...)
|
|
return rm.Reduce()
|
|
}
|
|
|
|
func (rm *ReadModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).AggregateIDs(rm.AggregateID)
|
|
}
|