2022-03-24 16:21:34 +00:00
|
|
|
package instance
|
2020-11-06 16:25:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
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
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DefaultOrgSetEvent) Payload() interface{} {
|
2020-11-06 16:25:07 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DefaultOrgSetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-03 12:30:39 +00:00
|
|
|
func NewDefaultOrgSetEventEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
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,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2022-06-03 12:30:39 +00:00
|
|
|
DefaultOrgSetEventType,
|
2020-11-06 16:25:07 +00:00
|
|
|
),
|
|
|
|
OrgID: orgID,
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 21:50:01 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func DefaultOrgSetMapper(event eventstore.Event) (eventstore.Event, error) {
|
2022-06-03 12:30:39 +00:00
|
|
|
e := &DefaultOrgSetEvent{
|
2020-11-12 21:50:01 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2020-11-12 21:50:01 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "IAM-cdFZH", "unable to unmarshal default org set")
|
2020-11-12 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|