mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 07:57:32 +00:00
chore: move the go code into a subfolder
This commit is contained in:
8
apps/api/internal/v2/system/aggregate.go
Normal file
8
apps/api/internal/v2/system/aggregate.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package system
|
||||
|
||||
const (
|
||||
AggregateType = "system"
|
||||
AggregateOwner = "SYSTEM"
|
||||
AggregateInstance = ""
|
||||
EventTypePrefix = AggregateType + "."
|
||||
)
|
44
apps/api/internal/v2/system/event.go
Normal file
44
apps/api/internal/v2/system/event.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
func init() {
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, IDGeneratedType, eventstore.GenericEventMapper[IDGeneratedEvent])
|
||||
}
|
||||
|
||||
const IDGeneratedType = AggregateType + ".id.generated"
|
||||
|
||||
type IDGeneratedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (e *IDGeneratedEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
||||
e.BaseEvent = *b
|
||||
}
|
||||
|
||||
func (e *IDGeneratedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *IDGeneratedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewIDGeneratedEvent(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
) *IDGeneratedEvent {
|
||||
return &IDGeneratedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
eventstore.NewAggregate(ctx, AggregateOwner, AggregateType, "v1"),
|
||||
IDGeneratedType),
|
||||
ID: id,
|
||||
}
|
||||
}
|
8
apps/api/internal/v2/system/mirror/aggregate.go
Normal file
8
apps/api/internal/v2/system/mirror/aggregate.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package mirror
|
||||
|
||||
import "github.com/zitadel/zitadel/internal/v2/system"
|
||||
|
||||
const (
|
||||
Creator = "MIRROR"
|
||||
eventTypePrefix = system.EventTypePrefix + "mirror."
|
||||
)
|
52
apps/api/internal/v2/system/mirror/failed.go
Normal file
52
apps/api/internal/v2/system/mirror/failed.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package mirror
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type failedPayload struct {
|
||||
Cause string `json:"cause"`
|
||||
// Source is the name of the database data are mirrored to
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
const FailedType = eventTypePrefix + "failed"
|
||||
|
||||
type FailedEvent eventstore.Event[failedPayload]
|
||||
|
||||
var _ eventstore.TypeChecker = (*FailedEvent)(nil)
|
||||
|
||||
func (e *FailedEvent) ActionType() string {
|
||||
return FailedType
|
||||
}
|
||||
|
||||
func FailedEventFromStorage(event *eventstore.StorageEvent) (e *FailedEvent, _ error) {
|
||||
if event.Type != e.ActionType() {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "MIRRO-bwB9l", "Errors.Invalid.Event.Type")
|
||||
}
|
||||
|
||||
payload, err := eventstore.UnmarshalPayload[failedPayload](event.Payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &FailedEvent{
|
||||
StorageEvent: event,
|
||||
Payload: payload,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewFailedCommand(source string, cause error) *eventstore.Command {
|
||||
return &eventstore.Command{
|
||||
Action: eventstore.Action[any]{
|
||||
Creator: Creator,
|
||||
Type: FailedType,
|
||||
Payload: failedPayload{
|
||||
Cause: cause.Error(),
|
||||
Source: source,
|
||||
},
|
||||
Revision: 1,
|
||||
},
|
||||
}
|
||||
}
|
68
apps/api/internal/v2/system/mirror/started.go
Normal file
68
apps/api/internal/v2/system/mirror/started.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package mirror
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type startedPayload struct {
|
||||
// Destination is the name of the database data are mirrored to
|
||||
Destination string `json:"destination"`
|
||||
// Either Instances or System needs to be set
|
||||
Instances []string `json:"instances,omitempty"`
|
||||
System bool `json:"system,omitempty"`
|
||||
}
|
||||
|
||||
const StartedType = eventTypePrefix + "started"
|
||||
|
||||
type StartedEvent eventstore.Event[startedPayload]
|
||||
|
||||
var _ eventstore.TypeChecker = (*StartedEvent)(nil)
|
||||
|
||||
func (e *StartedEvent) ActionType() string {
|
||||
return StartedType
|
||||
}
|
||||
|
||||
func StartedEventFromStorage(event *eventstore.StorageEvent) (e *StartedEvent, _ error) {
|
||||
if event.Type != e.ActionType() {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "MIRRO-bwB9l", "Errors.Invalid.Event.Type")
|
||||
}
|
||||
|
||||
payload, err := eventstore.UnmarshalPayload[startedPayload](event.Payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &StartedEvent{
|
||||
StorageEvent: event,
|
||||
Payload: payload,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewStartedSystemCommand(destination string) *eventstore.Command {
|
||||
return newStartedCommand(&startedPayload{
|
||||
Destination: destination,
|
||||
System: true,
|
||||
})
|
||||
}
|
||||
|
||||
func NewStartedInstancesCommand(destination string, instances []string) (*eventstore.Command, error) {
|
||||
if len(instances) == 0 {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "MIRRO-8YkrE", "Errors.Mirror.NoInstances")
|
||||
}
|
||||
return newStartedCommand(&startedPayload{
|
||||
Destination: destination,
|
||||
Instances: instances,
|
||||
}), nil
|
||||
}
|
||||
|
||||
func newStartedCommand(payload *startedPayload) *eventstore.Command {
|
||||
return &eventstore.Command{
|
||||
Action: eventstore.Action[any]{
|
||||
Creator: Creator,
|
||||
Type: StartedType,
|
||||
Revision: 1,
|
||||
Payload: *payload,
|
||||
},
|
||||
}
|
||||
}
|
55
apps/api/internal/v2/system/mirror/succeeded.go
Normal file
55
apps/api/internal/v2/system/mirror/succeeded.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package mirror
|
||||
|
||||
import (
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"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
|
||||
Position decimal.Decimal `json:"position"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func NewSucceededCommand(source string, position decimal.Decimal) *eventstore.Command {
|
||||
return &eventstore.Command{
|
||||
Action: eventstore.Action[any]{
|
||||
Creator: Creator,
|
||||
Type: SucceededType,
|
||||
Revision: 1,
|
||||
Payload: succeededPayload{
|
||||
Source: source,
|
||||
Position: position,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user