2021-07-05 15:10:49 +02: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 09:19:07 +01:00
|
|
|
func (wm *IAMCustomTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
2021-07-05 15:10:49 +02: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 13:55:57 +02:00
|
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
2021-07-05 15:10:49 +02:00
|
|
|
ResourceOwner(wm.ResourceOwner).
|
2021-07-06 13:55:57 +02:00
|
|
|
AddQuery().
|
|
|
|
AggregateIDs(wm.CustomTextWriteModel.AggregateID).
|
|
|
|
AggregateTypes(iam.AggregateType).
|
2021-07-05 15:10:49 +02:00
|
|
|
EventTypes(
|
2021-07-06 13:55:57 +02:00
|
|
|
iam.CustomTextSetEventType).
|
|
|
|
Builder()
|
2021-07-05 15:10:49 +02:00
|
|
|
}
|