2021-07-05 13:10:49 +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-07-05 13:10:49 +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-07-05 13:10:49 +00:00
|
|
|
)
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
type InstanceCustomTextWriteModel struct {
|
2021-07-05 13:10:49 +00:00
|
|
|
CustomTextWriteModel
|
|
|
|
}
|
|
|
|
|
2022-04-05 05:58:09 +00:00
|
|
|
func NewInstanceCustomTextWriteModel(ctx context.Context, key string, language language.Tag) *InstanceCustomTextWriteModel {
|
2022-03-24 16:21:34 +00:00
|
|
|
return &InstanceCustomTextWriteModel{
|
2021-07-05 13:10:49 +00:00
|
|
|
CustomTextWriteModel{
|
|
|
|
WriteModel: eventstore.WriteModel{
|
2022-04-05 05:58:09 +00:00
|
|
|
AggregateID: authz.GetInstance(ctx).InstanceID(),
|
|
|
|
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
|
2021-07-05 13:10:49 +00:00
|
|
|
},
|
|
|
|
Key: key,
|
|
|
|
Language: language,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func (wm *InstanceCustomTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
2021-07-05 13:10:49 +00:00
|
|
|
for _, event := range events {
|
|
|
|
switch e := event.(type) {
|
2022-03-24 16:21:34 +00:00
|
|
|
case *instance.CustomTextSetEvent:
|
2021-07-05 13:10:49 +00:00
|
|
|
wm.CustomTextWriteModel.AppendEvents(&e.CustomTextSetEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func (wm *InstanceCustomTextWriteModel) Reduce() error {
|
2021-07-05 13:10:49 +00:00
|
|
|
return wm.CustomTextWriteModel.Reduce()
|
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func (wm *InstanceCustomTextWriteModel) 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).
|
2022-03-24 16:21:34 +00:00
|
|
|
AggregateTypes(instance.AggregateType).
|
2021-07-05 13:10:49 +00:00
|
|
|
EventTypes(
|
2022-03-24 16:21:34 +00:00
|
|
|
instance.CustomTextSetEventType).
|
2021-07-06 11:55:57 +00:00
|
|
|
Builder()
|
2021-07-05 13:10:49 +00:00
|
|
|
}
|