mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-01 00:37:24 +00:00

* fix: split command query side * fix: split command query side * fix: members in correct pkg structure * fix: label policy in correct pkg structure * fix: structure * fix: structure of login policy * fix: identityprovider structure * fix: org iam policy structure * fix: password age policy structure * fix: password complexity policy structure * fix: password lockout policy structure * fix: idp structure * fix: user events structure * fix: user write model * fix: profile email changed command * fix: address changed command * fix: user states * fix: user * fix: org structure and add human * begin iam setup command side * setup * step2 * step2 * fix: add user * step2 * isvalid * fix: folder structure v2 business Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package eventstore
|
|
|
|
import "time"
|
|
|
|
//MemberWriteModel is the minimum representation of a command side view model.
|
|
// It implements a basic reducer
|
|
// it's purpose is to reduce events to create new ones
|
|
type WriteModel struct {
|
|
AggregateID string `json:"-"`
|
|
ProcessedSequence uint64 `json:"-"`
|
|
Events []EventReader `json:"-"`
|
|
ResourceOwner string `json:"-"`
|
|
ChangeDate time.Time `json:"-"`
|
|
}
|
|
|
|
//AppendEvents adds all the events to the read model.
|
|
// The function doesn't compute the new state of the read model
|
|
func (rm *WriteModel) AppendEvents(events ...EventReader) *WriteModel {
|
|
rm.Events = append(rm.Events, events...)
|
|
return rm
|
|
}
|
|
|
|
//Reduce is the basic implementaion of reducer
|
|
// If this function is extended the extending function should be the last step
|
|
func (wm *WriteModel) Reduce() error {
|
|
if len(wm.Events) == 0 {
|
|
return nil
|
|
}
|
|
|
|
if wm.AggregateID == "" {
|
|
wm.AggregateID = wm.Events[0].AggregateID()
|
|
}
|
|
if wm.ResourceOwner == "" {
|
|
wm.ResourceOwner = wm.Events[0].ResourceOwner()
|
|
}
|
|
|
|
wm.ProcessedSequence = wm.Events[len(wm.Events)-1].Sequence()
|
|
wm.ChangeDate = wm.Events[len(wm.Events)-1].CreationDate()
|
|
|
|
// all events processed and not needed anymore
|
|
wm.Events = nil
|
|
wm.Events = []EventReader{}
|
|
return nil
|
|
}
|