mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
12be21a3ff
creates events structures for initial projections and read models
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package user
|
|
|
|
import (
|
|
"golang.org/x/text/language"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
type humanProfileChangedPayload struct {
|
|
FirstName string `json:"firstName,omitempty"`
|
|
LastName string `json:"lastName,omitempty"`
|
|
NickName *string `json:"nickName,omitempty"`
|
|
DisplayName *string `json:"displayName,omitempty"`
|
|
PreferredLanguage *language.Tag `json:"preferredLanguage,omitempty"`
|
|
Gender *domain.Gender `json:"gender,omitempty"`
|
|
}
|
|
|
|
type HumanProfileChangedEvent eventstore.Event[humanProfileChangedPayload]
|
|
|
|
const HumanProfileChangedType = humanPrefix + ".profile.changed"
|
|
|
|
var _ eventstore.TypeChecker = (*HumanProfileChangedEvent)(nil)
|
|
|
|
// ActionType implements eventstore.Typer.
|
|
func (c *HumanProfileChangedEvent) ActionType() string {
|
|
return HumanProfileChangedType
|
|
}
|
|
|
|
func HumanProfileChangedEventFromStorage(event *eventstore.StorageEvent) (e *HumanProfileChangedEvent, _ error) {
|
|
if event.Type != e.ActionType() {
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "USER-Z1aFH", "Errors.Invalid.Event.Type")
|
|
}
|
|
|
|
payload, err := eventstore.UnmarshalPayload[humanProfileChangedPayload](event.Payload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &HumanProfileChangedEvent{
|
|
StorageEvent: event,
|
|
Payload: payload,
|
|
}, nil
|
|
}
|