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