zitadel/internal/v2/instance/domain_policy.go
Silvan 12be21a3ff
refactor(v2): init events (#7823)
creates events structures for initial projections and read models
2024-05-23 06:36:08 +02:00

66 lines
1.9 KiB
Go

package instance
import (
"github.com/zitadel/zitadel/internal/v2/eventstore"
"github.com/zitadel/zitadel/internal/v2/policy"
"github.com/zitadel/zitadel/internal/zerrors"
)
const DomainPolicyAddedType = eventTypePrefix + policy.DomainPolicyAddedTypeSuffix
type DomainPolicyAddedPayload policy.DomainPolicyAddedPayload
type DomainPolicyAddedEvent eventstore.Event[DomainPolicyAddedPayload]
var _ eventstore.TypeChecker = (*DomainPolicyAddedEvent)(nil)
// ActionType implements eventstore.Typer.
func (c *DomainPolicyAddedEvent) ActionType() string {
return DomainPolicyAddedType
}
func DomainPolicyAddedEventFromStorage(event *eventstore.StorageEvent) (e *DomainPolicyAddedEvent, _ error) {
if event.Type != e.ActionType() {
return nil, zerrors.ThrowInvalidArgument(nil, "INSTA-z1a7D", "Errors.Invalid.Event.Type")
}
payload, err := eventstore.UnmarshalPayload[DomainPolicyAddedPayload](event.Payload)
if err != nil {
return nil, err
}
return &DomainPolicyAddedEvent{
StorageEvent: event,
Payload: payload,
}, nil
}
const DomainPolicyChangedType = eventTypePrefix + policy.DomainPolicyChangedTypeSuffix
type DomainPolicyChangedPayload policy.DomainPolicyChangedPayload
type DomainPolicyChangedEvent eventstore.Event[DomainPolicyChangedPayload]
var _ eventstore.TypeChecker = (*DomainPolicyChangedEvent)(nil)
// ActionType implements eventstore.Typer.
func (c *DomainPolicyChangedEvent) ActionType() string {
return DomainPolicyChangedType
}
func DomainPolicyChangedEventFromStorage(event *eventstore.StorageEvent) (e *DomainPolicyChangedEvent, _ error) {
if event.Type != e.ActionType() {
return nil, zerrors.ThrowInvalidArgument(nil, "INSTA-BTLhd", "Errors.Invalid.Event.Type")
}
payload, err := eventstore.UnmarshalPayload[DomainPolicyChangedPayload](event.Payload)
if err != nil {
return nil, err
}
return &DomainPolicyChangedEvent{
StorageEvent: event,
Payload: payload,
}, nil
}