2024-05-30 09:35:30 +00:00
|
|
|
package mirror
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type succeededPayload struct {
|
|
|
|
// Source is the name of the database data are mirrored from
|
|
|
|
Source string `json:"source"`
|
|
|
|
// Position until data will be mirrored
|
2024-09-24 16:43:29 +00:00
|
|
|
Position float64 `json:"position"`
|
2024-05-30 09:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SucceededType = eventTypePrefix + "succeeded"
|
|
|
|
|
|
|
|
type SucceededEvent eventstore.Event[succeededPayload]
|
|
|
|
|
|
|
|
var _ eventstore.TypeChecker = (*SucceededEvent)(nil)
|
|
|
|
|
|
|
|
func (e *SucceededEvent) ActionType() string {
|
|
|
|
return SucceededType
|
|
|
|
}
|
|
|
|
|
|
|
|
func SucceededEventFromStorage(event *eventstore.StorageEvent) (e *SucceededEvent, _ error) {
|
|
|
|
if event.Type != e.ActionType() {
|
|
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "MIRRO-xh5IW", "Errors.Invalid.Event.Type")
|
|
|
|
}
|
|
|
|
|
|
|
|
payload, err := eventstore.UnmarshalPayload[succeededPayload](event.Payload)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &SucceededEvent{
|
|
|
|
StorageEvent: event,
|
|
|
|
Payload: payload,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-09-24 16:43:29 +00:00
|
|
|
func NewSucceededCommand(source string, position float64) *eventstore.Command {
|
2024-05-30 09:35:30 +00:00
|
|
|
return &eventstore.Command{
|
|
|
|
Action: eventstore.Action[any]{
|
|
|
|
Creator: Creator,
|
|
|
|
Type: SucceededType,
|
|
|
|
Revision: 1,
|
|
|
|
Payload: succeededPayload{
|
|
|
|
Source: source,
|
|
|
|
Position: position,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|