refactor(v2): init events (#7823)

creates events structures for initial projections and read models
This commit is contained in:
Silvan
2024-05-23 06:36:08 +02:00
committed by GitHub
parent f37113194d
commit 12be21a3ff
56 changed files with 1952 additions and 316 deletions

View File

@@ -0,0 +1,43 @@
package user
import (
"time"
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/v2/eventstore"
"github.com/zitadel/zitadel/internal/zerrors"
)
type humanInitCodeAddedPayload struct {
Code *crypto.CryptoValue `json:"code,omitempty"`
Expiry time.Duration `json:"expiry,omitempty"`
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
AuthRequestID string `json:"authRequestID,omitempty"`
}
type HumanInitCodeAddedEvent eventstore.Event[humanInitCodeAddedPayload]
const HumanInitCodeAddedType = humanPrefix + ".initialization.code.added"
var _ eventstore.TypeChecker = (*HumanInitCodeAddedEvent)(nil)
// ActionType implements eventstore.Typer.
func (c *HumanInitCodeAddedEvent) ActionType() string {
return HumanInitCodeAddedType
}
func HumanInitCodeAddedEventFromStorage(event *eventstore.StorageEvent) (e *HumanInitCodeAddedEvent, _ error) {
if event.Type != e.ActionType() {
return nil, zerrors.ThrowInvalidArgument(nil, "USER-XaGf6", "Errors.Invalid.Event.Type")
}
payload, err := eventstore.UnmarshalPayload[humanInitCodeAddedPayload](event.Payload)
if err != nil {
return nil, err
}
return &HumanInitCodeAddedEvent{
StorageEvent: event,
Payload: payload,
}, nil
}