2021-09-27 11:43:49 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/org"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OrgFlowWriteModel struct {
|
|
|
|
FlowWriteModel
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOrgFlowWriteModel(flowType domain.FlowType, resourceOwner string) *OrgFlowWriteModel {
|
|
|
|
return &OrgFlowWriteModel{
|
|
|
|
FlowWriteModel: *NewFlowWriteModel(flowType, resourceOwner),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func (wm *OrgFlowWriteModel) AppendEvents(events ...eventstore.Event) {
|
2021-09-27 11:43:49 +00:00
|
|
|
for _, event := range events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *org.TriggerActionsSetEvent:
|
|
|
|
if e.FlowType != wm.FlowType {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wm.FlowWriteModel.AppendEvents(&e.TriggerActionsSetEvent)
|
|
|
|
case *org.TriggerActionsCascadeRemovedEvent:
|
|
|
|
if e.FlowType != wm.FlowType {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wm.FlowWriteModel.AppendEvents(&e.TriggerActionsCascadeRemovedEvent)
|
|
|
|
case *org.FlowClearedEvent:
|
|
|
|
if e.FlowType != wm.FlowType {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wm.FlowWriteModel.AppendEvents(&e.FlowClearedEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *OrgFlowWriteModel) Reduce() error {
|
|
|
|
return wm.FlowWriteModel.Reduce()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *OrgFlowWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
|
|
ResourceOwner(wm.ResourceOwner).
|
|
|
|
AddQuery().
|
|
|
|
AggregateTypes(org.AggregateType).
|
|
|
|
EventTypes(org.TriggerActionsSetEventType,
|
|
|
|
org.TriggerActionsCascadeRemovedEventType,
|
|
|
|
org.FlowClearedEventType).
|
|
|
|
Builder()
|
|
|
|
}
|