zitadel/internal/repository/iam/event_org_set.go

56 lines
1.1 KiB
Go
Raw Normal View History

2020-11-06 17:25:07 +01:00
package iam
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/eventstore"
2020-11-06 17:25:07 +01:00
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/repository"
2020-11-06 17:25:07 +01:00
)
const (
GlobalOrgSetEventType eventstore.EventType = "iam.global.org.set"
)
type GlobalOrgSetEvent struct {
eventstore.BaseEvent `json:"-"`
OrgID string `json:"globalOrgId"`
}
func (e *GlobalOrgSetEvent) Data() interface{} {
return e
}
func (e *GlobalOrgSetEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewGlobalOrgSetEventEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
orgID string,
) *GlobalOrgSetEvent {
2020-11-06 17:25:07 +01:00
return &GlobalOrgSetEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
aggregate,
2020-11-06 17:25:07 +01:00
GlobalOrgSetEventType,
),
OrgID: orgID,
}
}
func GlobalOrgSetMapper(event *repository.Event) (eventstore.EventReader, error) {
e := &GlobalOrgSetEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "IAM-cdFZH", "unable to unmarshal global org set")
}
return e, nil
}