mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
00fec8830a
* fix: push events instead of aggregates * fix: tests * try without aggregate methods and with aggregate methods * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: change push aggregate to push events * fix: client secret * fix: query eventtypes * fix: query eventtypes * fix: eventstore index * fix: index * fix: merge new eventstore * fix: remove unnecessary todos * fix: remove unnecessary todos Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package command
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
|
"github.com/caos/zitadel/internal/v2/repository/org"
|
|
)
|
|
|
|
type OrgWriteModel struct {
|
|
eventstore.WriteModel
|
|
|
|
Name string
|
|
State domain.OrgState
|
|
PrimaryDomain string
|
|
}
|
|
|
|
func NewOrgWriteModel(orgID string) *OrgWriteModel {
|
|
return &OrgWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: orgID,
|
|
ResourceOwner: orgID,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *OrgWriteModel) Reduce() error {
|
|
for _, event := range wm.Events {
|
|
switch e := event.(type) {
|
|
case *org.OrgAddedEvent:
|
|
wm.Name = e.Name
|
|
wm.State = domain.OrgStateActive
|
|
case *org.OrgChangedEvent:
|
|
wm.Name = e.Name
|
|
case *org.DomainPrimarySetEvent:
|
|
wm.PrimaryDomain = e.Domain
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (wm *OrgWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, org.AggregateType).
|
|
AggregateIDs(wm.AggregateID).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
EventTypes(
|
|
org.OrgAddedEventType,
|
|
org.OrgChangedEventType,
|
|
org.OrgDomainPrimarySetEventType)
|
|
}
|
|
|
|
func OrgAggregateFromWriteModel(wm *eventstore.WriteModel) *eventstore.Aggregate {
|
|
return eventstore.AggregateFromWriteModel(wm, org.AggregateType, org.AggregateVersion)
|
|
}
|