2021-07-05 15:10:49 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-04-05 07:58:09 +02:00
|
|
|
"context"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2021-07-05 15:10:49 +02:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2021-07-05 15:10:49 +02:00
|
|
|
)
|
|
|
|
|
2022-03-24 17:21:34 +01:00
|
|
|
type InstanceCustomTextWriteModel struct {
|
2021-07-05 15:10:49 +02:00
|
|
|
CustomTextWriteModel
|
|
|
|
}
|
|
|
|
|
2022-04-05 07:58:09 +02:00
|
|
|
func NewInstanceCustomTextWriteModel(ctx context.Context, key string, language language.Tag) *InstanceCustomTextWriteModel {
|
2022-03-24 17:21:34 +01:00
|
|
|
return &InstanceCustomTextWriteModel{
|
2021-07-05 15:10:49 +02:00
|
|
|
CustomTextWriteModel{
|
|
|
|
WriteModel: eventstore.WriteModel{
|
2022-04-05 07:58:09 +02:00
|
|
|
AggregateID: authz.GetInstance(ctx).InstanceID(),
|
|
|
|
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
|
2021-07-05 15:10:49 +02:00
|
|
|
},
|
|
|
|
Key: key,
|
|
|
|
Language: language,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 17:21:34 +01:00
|
|
|
func (wm *InstanceCustomTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
2021-07-05 15:10:49 +02:00
|
|
|
for _, event := range events {
|
|
|
|
switch e := event.(type) {
|
2022-03-24 17:21:34 +01:00
|
|
|
case *instance.CustomTextSetEvent:
|
2021-07-05 15:10:49 +02:00
|
|
|
wm.CustomTextWriteModel.AppendEvents(&e.CustomTextSetEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 17:21:34 +01:00
|
|
|
func (wm *InstanceCustomTextWriteModel) Reduce() error {
|
2021-07-05 15:10:49 +02:00
|
|
|
return wm.CustomTextWriteModel.Reduce()
|
|
|
|
}
|
|
|
|
|
2022-03-24 17:21:34 +01:00
|
|
|
func (wm *InstanceCustomTextWriteModel) 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).
|
2022-03-24 17:21:34 +01:00
|
|
|
AggregateTypes(instance.AggregateType).
|
2021-07-05 15:10:49 +02:00
|
|
|
EventTypes(
|
2022-03-24 17:21:34 +01:00
|
|
|
instance.CustomTextSetEventType).
|
2021-07-06 13:55:57 +02:00
|
|
|
Builder()
|
2021-07-05 15:10:49 +02:00
|
|
|
}
|