mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
12be21a3ff
creates events structures for initial projections and read models
38 lines
864 B
Go
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
|
|
}
|