zitadel/internal/repository/user/human_address.go
Fabi d8e42744b4
fix: move v2 pkgs (#1331)
* fix: move eventstore pkgs

* fix: move eventstore pkgs

* fix: remove v2 view

* fix: remove v2 view
2021-02-23 15:13:04 +01:00

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
}