2021-06-10 13:49:10 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-04-05 07:58:09 +02:00
|
|
|
"context"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2021-06-10 13:49:10 +02:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2021-06-10 13:49:10 +02:00
|
|
|
)
|
|
|
|
|
2022-03-28 10:05:09 +02:00
|
|
|
type InstanceCustomMessageTextWriteModel struct {
|
2021-06-10 13:49:10 +02:00
|
|
|
CustomMessageTextReadModel
|
|
|
|
}
|
|
|
|
|
2022-04-05 07:58:09 +02:00
|
|
|
func NewInstanceCustomMessageTextWriteModel(ctx context.Context, messageTextType string, lang language.Tag) *InstanceCustomMessageTextWriteModel {
|
2022-03-28 10:05:09 +02:00
|
|
|
return &InstanceCustomMessageTextWriteModel{
|
2021-06-10 13:49:10 +02:00
|
|
|
CustomMessageTextReadModel{
|
|
|
|
WriteModel: eventstore.WriteModel{
|
2022-04-05 07:58:09 +02:00
|
|
|
AggregateID: authz.GetInstance(ctx).InstanceID(),
|
|
|
|
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
|
2021-06-10 13:49:10 +02:00
|
|
|
},
|
|
|
|
MessageTextType: messageTextType,
|
|
|
|
Language: lang,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 10:05:09 +02:00
|
|
|
func (wm *InstanceCustomMessageTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
2021-06-10 13:49:10 +02:00
|
|
|
for _, event := range events {
|
|
|
|
switch e := event.(type) {
|
2022-03-24 17:21:34 +01:00
|
|
|
case *instance.CustomTextSetEvent:
|
2021-06-10 13:49:10 +02:00
|
|
|
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextSetEvent)
|
2022-03-24 17:21:34 +01:00
|
|
|
case *instance.CustomTextRemovedEvent:
|
2022-02-04 10:25:25 +01:00
|
|
|
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextRemovedEvent)
|
2022-03-24 17:21:34 +01:00
|
|
|
case *instance.CustomTextTemplateRemovedEvent:
|
2022-02-04 10:25:25 +01:00
|
|
|
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextTemplateRemovedEvent)
|
2021-06-10 13:49:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 10:05:09 +02:00
|
|
|
func (wm *InstanceCustomMessageTextWriteModel) Reduce() error {
|
2021-06-10 13:49:10 +02:00
|
|
|
return wm.CustomMessageTextReadModel.Reduce()
|
|
|
|
}
|
|
|
|
|
2022-03-28 10:05:09 +02:00
|
|
|
func (wm *InstanceCustomMessageTextWriteModel) Query() *eventstore.SearchQueryBuilder {
|
2021-07-06 13:55:57 +02:00
|
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
2021-06-10 13:49:10 +02:00
|
|
|
ResourceOwner(wm.ResourceOwner).
|
2021-07-06 13:55:57 +02:00
|
|
|
AddQuery().
|
2022-03-24 17:21:34 +01:00
|
|
|
AggregateTypes(instance.AggregateType).
|
2021-07-06 13:55:57 +02:00
|
|
|
AggregateIDs(wm.CustomMessageTextReadModel.AggregateID).
|
2022-03-24 17:21:34 +01:00
|
|
|
EventTypes(instance.CustomTextSetEventType, instance.CustomTextRemovedEventType, instance.CustomTextTemplateRemovedEventType).
|
2021-07-06 13:55:57 +02:00
|
|
|
Builder()
|
2021-06-10 13:49:10 +02:00
|
|
|
}
|