zitadel/internal/repository/instance/event_org_set.go

57 lines
1.1 KiB
Go
Raw Normal View History

package instance
2020-11-06 16:25:07 +00:00
import (
"context"
"encoding/json"
"github.com/zitadel/zitadel/internal/eventstore"
2020-11-06 16:25:07 +00:00
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore/repository"
2020-11-06 16:25:07 +00:00
)
const (
2022-06-03 12:30:39 +00:00
DefaultOrgSetEventType eventstore.EventType = "instance.default.org.set"
2020-11-06 16:25:07 +00:00
)
2022-06-03 12:30:39 +00:00
type DefaultOrgSetEvent struct {
2020-11-06 16:25:07 +00:00
eventstore.BaseEvent `json:"-"`
2022-06-03 12:30:39 +00:00
OrgID string `json:"orgId"`
2020-11-06 16:25:07 +00:00
}
2022-06-03 12:30:39 +00:00
func (e *DefaultOrgSetEvent) Data() interface{} {
2020-11-06 16:25:07 +00:00
return e
}
2022-06-03 12:30:39 +00:00
func (e *DefaultOrgSetEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
2022-06-03 12:30:39 +00:00
func NewDefaultOrgSetEventEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
orgID string,
2022-06-03 12:30:39 +00:00
) *DefaultOrgSetEvent {
return &DefaultOrgSetEvent{
2020-11-06 16:25:07 +00:00
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
aggregate,
2022-06-03 12:30:39 +00:00
DefaultOrgSetEventType,
2020-11-06 16:25:07 +00:00
),
OrgID: orgID,
}
}
2022-06-03 12:30:39 +00:00
func DefaultOrgSetMapper(event *repository.Event) (eventstore.Event, error) {
e := &DefaultOrgSetEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
2022-06-03 12:30:39 +00:00
return nil, errors.ThrowInternal(err, "IAM-cdFZH", "unable to unmarshal default org set")
}
return e, nil
}