zitadel/internal/v2/repository/user/human_address.go
Fabi 28bfe72930
feat: uniqueness (#1190)
* feat: uniqueness on events

* fix: some tests

* fix: add unique username

* fix: nice error message

* fix: add unique test

* fix: add unique test

* fix: add unique constraint to events

* fix: correct unique constraint on user events

* fix: remove user constraint

* fix: add unique constraints

* fix: add unique constraints

* fix: add unique constraints

* fix: unnique constraints without interface

* fix: unique idp config

* fix: unique constraint comments

* fix: unique constraints in one table

* fix: unique constraints error

* fix: fix unique constraint on create user

* fix: fix unique constraint on create project

* fix: fix unique constraint on idp configs
2021-01-21 10:49:38 +01:00

54 lines
1.4 KiB
Go

package user
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 (
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) *HumanAddressChangedEvent {
return &HumanAddressChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
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
}