zitadel/internal/v2/org/changed.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

38 lines
864 B
Go

package org
import (
"github.com/zitadel/zitadel/internal/v2/eventstore"
"github.com/zitadel/zitadel/internal/zerrors"
)
const ChangedType = eventTypePrefix + "changed"
type changedPayload struct {
Name string `json:"name"`
}
type ChangedEvent eventstore.Event[changedPayload]
var _ eventstore.TypeChecker = (*ChangedEvent)(nil)
// ActionType implements eventstore.Typer.
func (c *ChangedEvent) ActionType() string {
return ChangedType
}
func ChangedEventFromStorage(event *eventstore.StorageEvent) (e *ChangedEvent, _ error) {
if event.Type != e.ActionType() {
return nil, zerrors.ThrowInvalidArgument(nil, "ORG-pzOfP", "Errors.Invalid.Event.Type")
}
payload, err := eventstore.UnmarshalPayload[changedPayload](event.Payload)
if err != nil {
return nil, err
}
return &ChangedEvent{
StorageEvent: event,
Payload: payload,
}, nil
}