zitadel/internal/command/policy_mail_text_model.go
Fabi d8e42744b4
fix: move v2 pkgs (#1331)
* fix: move eventstore pkgs

* fix: move eventstore pkgs

* fix: remove v2 view

* fix: remove v2 view
2021-02-23 15:13:04 +01:00

66 lines
1.4 KiB
Go

package command
import (
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/policy"
)
type MailTextWriteModel struct {
eventstore.WriteModel
MailTextType string
Language string
Title string
PreHeader string
Subject string
Greeting string
Text string
ButtonText string
State domain.PolicyState
}
func (wm *MailTextWriteModel) Reduce() error {
for _, event := range wm.Events {
switch e := event.(type) {
case *policy.MailTextAddedEvent:
if wm.MailTextType != e.MailTextType || wm.Language != e.Language {
continue
}
wm.Title = e.Title
wm.PreHeader = e.PreHeader
wm.Subject = e.Subject
wm.Greeting = e.Greeting
wm.Text = e.Text
wm.ButtonText = e.ButtonText
wm.State = domain.PolicyStateActive
case *policy.MailTextChangedEvent:
if wm.MailTextType != e.MailTextType || wm.Language != e.Language {
continue
}
if e.Title != nil {
wm.Title = *e.Title
}
if e.PreHeader != nil {
wm.PreHeader = *e.PreHeader
}
if e.Subject != nil {
wm.Subject = *e.Subject
}
if e.Greeting != nil {
wm.Greeting = *e.Greeting
}
if e.Text != nil {
wm.Text = *e.Text
}
if e.ButtonText != nil {
wm.ButtonText = *e.ButtonText
}
case *policy.MailTextRemovedEvent:
wm.State = domain.PolicyStateRemoved
}
}
return wm.WriteModel.Reduce()
}