mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:47:32 +00:00
refactor(v2): init events (#7823)
creates events structures for initial projections and read models
This commit is contained in:
8
internal/v2/instance/aggregate.go
Normal file
8
internal/v2/instance/aggregate.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package instance
|
||||
|
||||
import "github.com/zitadel/zitadel/internal/repository/instance"
|
||||
|
||||
const (
|
||||
AggregateType = string(instance.AggregateType)
|
||||
eventTypePrefix = AggregateType + "."
|
||||
)
|
65
internal/v2/instance/domain_policy.go
Normal file
65
internal/v2/instance/domain_policy.go
Normal file
@@ -0,0 +1,65 @@
|
||||
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
|
||||
}
|
27
internal/v2/instance/removed.go
Normal file
27
internal/v2/instance/removed.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package instance
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
const RemovedType = eventTypePrefix + "removed"
|
||||
|
||||
type RemovedEvent eventstore.Event[eventstore.EmptyPayload]
|
||||
|
||||
var _ eventstore.TypeChecker = (*RemovedEvent)(nil)
|
||||
|
||||
// ActionType implements eventstore.Typer.
|
||||
func (c *RemovedEvent) ActionType() string {
|
||||
return RemovedType
|
||||
}
|
||||
|
||||
func RemovedEventFromStorage(event *eventstore.StorageEvent) (e *RemovedEvent, _ error) {
|
||||
if event.Type != e.ActionType() {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "INSTA-xppIg", "Errors.Invalid.Event.Type")
|
||||
}
|
||||
|
||||
return &RemovedEvent{
|
||||
StorageEvent: event,
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user