2022-03-24 16:21:34 +00:00
|
|
|
package instance
|
2022-02-16 15:49:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2022-02-16 15:49:17 +00:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
2022-02-16 15:49:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DefaultLanguageSetEventType eventstore.EventType = "iam.default.language.set"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DefaultLanguageSetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Language language.Tag `json:"language"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DefaultLanguageSetEvent) Data() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DefaultLanguageSetEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultLanguageSetEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
language language.Tag,
|
|
|
|
) *DefaultLanguageSetEvent {
|
|
|
|
return &DefaultLanguageSetEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
DefaultLanguageSetEventType,
|
|
|
|
),
|
|
|
|
Language: language,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultLanguageSetMapper(event *repository.Event) (eventstore.Event, error) {
|
|
|
|
e := &DefaultLanguageSetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "IAM-3j9fs", "unable to unmarshal default language set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|