mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
35 lines
761 B
Go
35 lines
761 B
Go
|
package command
|
||
|
|
||
|
import (
|
||
|
"golang.org/x/text/language"
|
||
|
|
||
|
"github.com/caos/zitadel/internal/domain"
|
||
|
"github.com/caos/zitadel/internal/eventstore"
|
||
|
"github.com/caos/zitadel/internal/repository/policy"
|
||
|
)
|
||
|
|
||
|
type CustomTextWriteModel struct {
|
||
|
eventstore.WriteModel
|
||
|
|
||
|
Key string
|
||
|
Language language.Tag
|
||
|
Text string
|
||
|
State domain.CustomTextState
|
||
|
}
|
||
|
|
||
|
func (wm *CustomTextWriteModel) Reduce() error {
|
||
|
for _, event := range wm.Events {
|
||
|
switch e := event.(type) {
|
||
|
case *policy.CustomTextSetEvent:
|
||
|
if wm.Key != e.Key || wm.Language != e.Language {
|
||
|
continue
|
||
|
}
|
||
|
wm.Text = e.Text
|
||
|
wm.State = domain.CustomTextStateActive
|
||
|
case *policy.CustomTextRemovedEvent:
|
||
|
wm.State = domain.CustomTextStateRemoved
|
||
|
}
|
||
|
}
|
||
|
return wm.WriteModel.Reduce()
|
||
|
}
|