2021-01-04 13:52:13 +00:00
|
|
|
package user
|
2020-12-10 15:18:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-01-04 13:52:13 +00:00
|
|
|
addressEventPrefix = humanEventPrefix + "address."
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanAddressChangedType = addressEventPrefix + "changed"
|
|
|
|
)
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanAddressChangedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
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"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanAddressChangedEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewHumanAddressChangedEvent(ctx context.Context) *HumanAddressChangedEvent {
|
|
|
|
return &HumanAddressChangedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
HumanAddressChangedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func HumanAddressChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
addressChanged := &HumanAddressChangedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
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
|
|
|
|
}
|