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