2021-07-05 13:10:49 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/iam"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IAMCustomTextWriteModel struct {
|
|
|
|
CustomTextWriteModel
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIAMCustomTextWriteModel(key string, language language.Tag) *IAMCustomTextWriteModel {
|
|
|
|
return &IAMCustomTextWriteModel{
|
|
|
|
CustomTextWriteModel{
|
|
|
|
WriteModel: eventstore.WriteModel{
|
|
|
|
AggregateID: domain.IAMID,
|
|
|
|
ResourceOwner: domain.IAMID,
|
|
|
|
},
|
|
|
|
Key: key,
|
|
|
|
Language: language,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func (wm *IAMCustomTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
2021-07-05 13:10:49 +00:00
|
|
|
for _, event := range events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *iam.CustomTextSetEvent:
|
|
|
|
wm.CustomTextWriteModel.AppendEvents(&e.CustomTextSetEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *IAMCustomTextWriteModel) Reduce() error {
|
|
|
|
return wm.CustomTextWriteModel.Reduce()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *IAMCustomTextWriteModel) Query() *eventstore.SearchQueryBuilder {
|
2021-07-06 11:55:57 +00:00
|
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
2021-07-05 13:10:49 +00:00
|
|
|
ResourceOwner(wm.ResourceOwner).
|
2021-07-06 11:55:57 +00:00
|
|
|
AddQuery().
|
|
|
|
AggregateIDs(wm.CustomTextWriteModel.AggregateID).
|
|
|
|
AggregateTypes(iam.AggregateType).
|
2021-07-05 13:10:49 +00:00
|
|
|
EventTypes(
|
2021-07-06 11:55:57 +00:00
|
|
|
iam.CustomTextSetEventType).
|
|
|
|
Builder()
|
2021-07-05 13:10:49 +00:00
|
|
|
}
|