mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
d8e42744b4
* fix: move eventstore pkgs * fix: move eventstore pkgs * fix: remove v2 view * fix: remove v2 view
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
)
|
|
|
|
const (
|
|
addressEventPrefix = humanEventPrefix + "address."
|
|
HumanAddressChangedType = addressEventPrefix + "changed"
|
|
)
|
|
|
|
type HumanAddressChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
Country *string `json:"country,omitempty"`
|
|
Locality *string `json:"locality,omitempty"`
|
|
PostalCode *string `json:"postalCode,omitempty"`
|
|
Region *string `json:"region,omitempty"`
|
|
StreetAddress *string `json:"streetAddress,omitempty"`
|
|
}
|
|
|
|
func (e *HumanAddressChangedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *HumanAddressChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanAddressChangedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanAddressChangedEvent {
|
|
return &HumanAddressChangedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanAddressChangedType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanAddressChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
addressChanged := &HumanAddressChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
err := json.Unmarshal(event.Data, addressChanged)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "USER-5M0pd", "unable to unmarshal human address changed")
|
|
}
|
|
|
|
return addressChanged, nil
|
|
}
|