zitadel/internal/command/instance_custom_message_text_model.go
Tim Möhlmann 25ef3da9d5
refactor(fmt): run gci on complete project (#7557)
chore(fmt): run gci on complete project

Fix global import formatting in go code by running the `gci` command. This allows us to just use the command directly, instead of fixing the import order manually for the linter, on each PR.

Co-authored-by: Elio Bischof <elio@zitadel.com>
2024-04-03 10:43:43 +00:00

56 lines
1.8 KiB
Go

package command
import (
"context"
"golang.org/x/text/language"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/repository/instance"
)
type InstanceCustomMessageTextWriteModel struct {
CustomMessageTextReadModel
}
func NewInstanceCustomMessageTextWriteModel(ctx context.Context, messageTextType string, lang language.Tag) *InstanceCustomMessageTextWriteModel {
return &InstanceCustomMessageTextWriteModel{
CustomMessageTextReadModel{
WriteModel: eventstore.WriteModel{
AggregateID: authz.GetInstance(ctx).InstanceID(),
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
},
MessageTextType: messageTextType,
Language: lang,
},
}
}
func (wm *InstanceCustomMessageTextWriteModel) AppendEvents(events ...eventstore.Event) {
for _, event := range events {
switch e := event.(type) {
case *instance.CustomTextSetEvent:
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextSetEvent)
case *instance.CustomTextRemovedEvent:
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextRemovedEvent)
case *instance.CustomTextTemplateRemovedEvent:
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextTemplateRemovedEvent)
}
}
}
func (wm *InstanceCustomMessageTextWriteModel) Reduce() error {
return wm.CustomMessageTextReadModel.Reduce()
}
func (wm *InstanceCustomMessageTextWriteModel) Query() *eventstore.SearchQueryBuilder {
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
ResourceOwner(wm.ResourceOwner).
AddQuery().
AggregateTypes(instance.AggregateType).
AggregateIDs(wm.CustomMessageTextReadModel.AggregateID).
EventTypes(instance.CustomTextSetEventType, instance.CustomTextRemovedEventType, instance.CustomTextTemplateRemovedEventType).
Builder()
}