mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +00:00
refactor(v2): init events (#7823)
creates events structures for initial projections and read models
This commit is contained in:
94
internal/v2/org/domain_policy.go
Normal file
94
internal/v2/org/domain_policy.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package org
|
||||
|
||||
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, "ORG-asiSN", "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, "ORG-BmN6K", "Errors.Invalid.Event.Type")
|
||||
}
|
||||
|
||||
payload, err := eventstore.UnmarshalPayload[DomainPolicyChangedPayload](event.Payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DomainPolicyChangedEvent{
|
||||
StorageEvent: event,
|
||||
Payload: payload,
|
||||
}, nil
|
||||
}
|
||||
|
||||
const DomainPolicyRemovedType = eventTypePrefix + policy.DomainPolicyRemovedTypeSuffix
|
||||
|
||||
type DomainPolicyRemovedPayload policy.DomainPolicyRemovedPayload
|
||||
|
||||
type DomainPolicyRemovedEvent eventstore.Event[DomainPolicyRemovedPayload]
|
||||
|
||||
var _ eventstore.TypeChecker = (*DomainPolicyRemovedEvent)(nil)
|
||||
|
||||
// ActionType implements eventstore.Typer.
|
||||
func (c *DomainPolicyRemovedEvent) ActionType() string {
|
||||
return DomainPolicyRemovedType
|
||||
}
|
||||
|
||||
func DomainPolicyRemovedEventFromStorage(event *eventstore.StorageEvent) (e *DomainPolicyRemovedEvent, _ error) {
|
||||
if event.Type != e.ActionType() {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "ORG-nHy4z", "Errors.Invalid.Event.Type")
|
||||
}
|
||||
|
||||
payload, err := eventstore.UnmarshalPayload[DomainPolicyRemovedPayload](event.Payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DomainPolicyRemovedEvent{
|
||||
StorageEvent: event,
|
||||
Payload: payload,
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user