2020-11-12 21:50:01 +00:00
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
2020-12-11 14:49:19 +00:00
|
|
|
"github.com/caos/zitadel/internal/v2/repository/policy/label"
|
2020-11-12 21:50:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-12-11 14:49:19 +00:00
|
|
|
LabelPolicyAddedEventType = orgEventTypePrefix + label.LabelPolicyAddedEventType
|
|
|
|
LabelPolicyChangedEventType = orgEventTypePrefix + label.LabelPolicyChangedEventType
|
2020-11-12 21:50:01 +00:00
|
|
|
)
|
|
|
|
|
2020-12-11 14:49:19 +00:00
|
|
|
type LabelPolicyReadModel struct{ label.ReadModel }
|
2020-11-12 21:50:01 +00:00
|
|
|
|
2020-11-25 13:12:44 +00:00
|
|
|
func (rm *LabelPolicyReadModel) AppendEvents(events ...eventstore.EventReader) {
|
2020-11-12 21:50:01 +00:00
|
|
|
for _, event := range events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *LabelPolicyAddedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
rm.ReadModel.AppendEvents(&e.AddedEvent)
|
2020-11-12 21:50:01 +00:00
|
|
|
case *LabelPolicyChangedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
rm.ReadModel.AppendEvents(&e.ChangedEvent)
|
|
|
|
case *label.AddedEvent, *label.ChangedEvent:
|
2020-11-12 21:50:01 +00:00
|
|
|
rm.ReadModel.AppendEvents(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type LabelPolicyAddedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
label.AddedEvent
|
2020-11-12 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LabelPolicyChangedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
label.ChangedEvent
|
2020-11-12 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 14:49:19 +00:00
|
|
|
// func NewAddedEvent(
|
2020-11-12 21:50:01 +00:00
|
|
|
// ctx context.Context,
|
|
|
|
// primaryColor,
|
|
|
|
// secondaryColor string,
|
2020-12-11 14:49:19 +00:00
|
|
|
// ) *AddedEvent {
|
2020-11-12 21:50:01 +00:00
|
|
|
|
2020-12-11 14:49:19 +00:00
|
|
|
// return &AddedEvent{
|
|
|
|
// AddedEvent: *policy.NewAddedEvent(
|
2020-11-12 21:50:01 +00:00
|
|
|
// ctx,
|
|
|
|
// primaryColor,
|
|
|
|
// secondaryColor,
|
|
|
|
// ),
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2020-12-11 14:49:19 +00:00
|
|
|
// func NewChangedEvent(
|
2020-11-12 21:50:01 +00:00
|
|
|
// ctx context.Context,
|
|
|
|
// primaryColor,
|
|
|
|
// secondaryColor string,
|
|
|
|
// ) *MemberChangedEvent {
|
|
|
|
|
2020-12-11 14:49:19 +00:00
|
|
|
// return &ChangedEvent{
|
|
|
|
// ChangedEvent: *policy.NewChangedEvent(
|
2020-11-12 21:50:01 +00:00
|
|
|
// ctx,
|
|
|
|
// primaryColor,
|
|
|
|
// secondaryColor,
|
|
|
|
// ),
|
|
|
|
// }
|
|
|
|
// }
|