2021-02-10 09:48:40 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2021-02-10 09:48:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|