zitadel/internal/v2/user/human_profile_changed.go
Silvan 12be21a3ff
refactor(v2): init events (#7823)
creates events structures for initial projections and read models
2024-05-23 06:36:08 +02:00

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
}