2021-02-10 09:48:40 +00:00
|
|
|
package iam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 08:19:07 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2021-02-10 09:48:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
MailTemplateAddedEventType = iamEventTypePrefix + policy.MailTemplatePolicyAddedEventType
|
|
|
|
MailTemplateChangedEventType = iamEventTypePrefix + policy.MailTemplatePolicyChangedEventType
|
|
|
|
)
|
|
|
|
|
|
|
|
type MailTemplateAddedEvent struct {
|
|
|
|
policy.MailTemplateAddedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMailTemplateAddedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-02-10 09:48:40 +00:00
|
|
|
template []byte,
|
|
|
|
) *MailTemplateAddedEvent {
|
|
|
|
return &MailTemplateAddedEvent{
|
|
|
|
MailTemplateAddedEvent: *policy.NewMailTemplateAddedEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
eventstore.NewBaseEventForPush(ctx, aggregate, MailTemplateAddedEventType),
|
2021-02-10 09:48:40 +00:00
|
|
|
template),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func MailTemplateAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-02-10 09:48:40 +00:00
|
|
|
e, err := policy.MailTemplateAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MailTemplateAddedEvent{MailTemplateAddedEvent: *e.(*policy.MailTemplateAddedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type MailTemplateChangedEvent struct {
|
|
|
|
policy.MailTemplateChangedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMailTemplateChangedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-02-10 09:48:40 +00:00
|
|
|
changes []policy.MailTemplateChanges,
|
|
|
|
) (*MailTemplateChangedEvent, error) {
|
|
|
|
changedEvent, err := policy.NewMailTemplateChangedEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
eventstore.NewBaseEventForPush(ctx, aggregate, MailTemplateChangedEventType),
|
2021-02-10 09:48:40 +00:00
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &MailTemplateChangedEvent{MailTemplateChangedEvent: *changedEvent}, nil
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func MailTemplateChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-02-10 09:48:40 +00:00
|
|
|
e, err := policy.MailTemplateChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MailTemplateChangedEvent{MailTemplateChangedEvent: *e.(*policy.MailTemplateChangedEvent)}, nil
|
|
|
|
}
|