mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-05 08:02:07 +00:00
reduce milestone pushed
This commit is contained in:
@@ -2,215 +2,49 @@ package milestone
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
type PushedEventType eventstore.EventType
|
||||
|
||||
const (
|
||||
eventTypePrefix = PushedEventType("milestone.pushed.")
|
||||
PushedInstanceCreatedEventType = eventTypePrefix + "instance.created"
|
||||
PushedAuthenticationSucceededOnInstanceEventType = eventTypePrefix + "instance.authentication.succeeded"
|
||||
PushedProjectCreatedEventType = eventTypePrefix + "project.created"
|
||||
PushedApplicationCreatedEventType = eventTypePrefix + "application.created"
|
||||
PushedAuthenticationSucceededOnApplicationEventType = eventTypePrefix + "application.authentication.succeeded"
|
||||
PushedInstanceDeletedEventType = eventTypePrefix + "instance.deleted"
|
||||
eventTypePrefix = eventstore.EventType("milestone.")
|
||||
PushedEventType = eventTypePrefix + "pushed"
|
||||
)
|
||||
|
||||
func PushedEventTypes() []PushedEventType {
|
||||
return []PushedEventType{
|
||||
PushedInstanceCreatedEventType,
|
||||
PushedAuthenticationSucceededOnInstanceEventType,
|
||||
PushedProjectCreatedEventType,
|
||||
PushedApplicationCreatedEventType,
|
||||
PushedAuthenticationSucceededOnApplicationEventType,
|
||||
PushedInstanceDeletedEventType,
|
||||
}
|
||||
type PushedEvent struct {
|
||||
*eventstore.BaseEvent `json:"-"`
|
||||
MilestoneType Type `json:"type"`
|
||||
PrimaryDomain string `json:"primaryDomain"`
|
||||
Endpoints []string `json:"endpoints"`
|
||||
}
|
||||
|
||||
type PushedEvent interface {
|
||||
eventstore.Command
|
||||
IsMilestoneEvent()
|
||||
func (p *PushedEvent) Data() interface{} {
|
||||
return p
|
||||
}
|
||||
|
||||
type basePushedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
PrimaryDomain string `json:"primaryDomain"`
|
||||
Endpoints []string `json:"endpoints"`
|
||||
}
|
||||
|
||||
func (b *basePushedEvent) Data() interface{} {
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *basePushedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (p *PushedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *basePushedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
||||
b.BaseEvent = *base
|
||||
func (p *PushedEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
||||
p.BaseEvent = b
|
||||
}
|
||||
|
||||
func NewPushedEventByType(
|
||||
ctx context.Context,
|
||||
eventType PushedEventType,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) (PushedEvent, error) {
|
||||
switch eventType {
|
||||
case PushedInstanceCreatedEventType:
|
||||
return NewInstanceCreatedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedAuthenticationSucceededOnInstanceEventType:
|
||||
return NewAuthenticationSucceededOnInstancePushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedProjectCreatedEventType:
|
||||
return NewProjectCreatedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedApplicationCreatedEventType:
|
||||
return NewApplicationCreatedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedAuthenticationSucceededOnApplicationEventType:
|
||||
return NewAuthenticationSucceededOnApplicationPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
case PushedInstanceDeletedEventType:
|
||||
return NewInstanceDeletedPushedEvent(ctx, aggregate, endpoints, primaryDomain), nil
|
||||
}
|
||||
return nil, fmt.Errorf("unknown event type %s", eventType)
|
||||
}
|
||||
|
||||
type InstanceCreatedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *InstanceCreatedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewInstanceCreatedPushedEvent(
|
||||
func NewPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
msType Type,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *InstanceCreatedPushedEvent {
|
||||
return &InstanceCreatedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedInstanceCreatedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type AuthenticationSucceededOnInstancePushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *AuthenticationSucceededOnInstancePushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewAuthenticationSucceededOnInstancePushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *AuthenticationSucceededOnInstancePushedEvent {
|
||||
return &AuthenticationSucceededOnInstancePushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedAuthenticationSucceededOnInstanceEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ProjectCreatedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *ProjectCreatedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewProjectCreatedPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *ProjectCreatedPushedEvent {
|
||||
return &ProjectCreatedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedProjectCreatedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ApplicationCreatedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *ApplicationCreatedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewApplicationCreatedPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *ApplicationCreatedPushedEvent {
|
||||
return &ApplicationCreatedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedApplicationCreatedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type AuthenticationSucceededOnApplicationPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *AuthenticationSucceededOnApplicationPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewAuthenticationSucceededOnApplicationPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *AuthenticationSucceededOnApplicationPushedEvent {
|
||||
return &AuthenticationSucceededOnApplicationPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedAuthenticationSucceededOnApplicationEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type InstanceDeletedPushedEvent struct{ basePushedEvent }
|
||||
|
||||
func (e *InstanceDeletedPushedEvent) IsMilestoneEvent() {}
|
||||
|
||||
func NewInstanceDeletedPushedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *Aggregate,
|
||||
endpoints []string,
|
||||
primaryDomain string,
|
||||
) *InstanceDeletedPushedEvent {
|
||||
return &InstanceDeletedPushedEvent{
|
||||
basePushedEvent: basePushedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
eventstore.EventType(PushedInstanceDeletedEventType),
|
||||
),
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
},
|
||||
) *PushedEvent {
|
||||
return &PushedEvent{
|
||||
BaseEvent: eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
&aggregate.Aggregate,
|
||||
PushedEventType,
|
||||
),
|
||||
MilestoneType: msType,
|
||||
Endpoints: endpoints,
|
||||
PrimaryDomain: primaryDomain,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,5 @@ import (
|
||||
)
|
||||
|
||||
func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
es.RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedProjectCreatedEventType), eventstore.GenericEventMapper[InstanceCreatedPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedAuthenticationSucceededOnInstanceEventType), eventstore.GenericEventMapper[AuthenticationSucceededOnInstancePushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedProjectCreatedEventType), eventstore.GenericEventMapper[ProjectCreatedPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedApplicationCreatedEventType), eventstore.GenericEventMapper[ApplicationCreatedPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedAuthenticationSucceededOnApplicationEventType), eventstore.GenericEventMapper[AuthenticationSucceededOnApplicationPushedEvent]).
|
||||
RegisterFilterEventMapper(AggregateType, eventstore.EventType(PushedInstanceDeletedEventType), eventstore.GenericEventMapper[InstanceDeletedPushedEvent])
|
||||
es.RegisterFilterEventMapper(AggregateType, PushedEventType, eventstore.GenericEventMapper[PushedEvent])
|
||||
}
|
||||
|
||||
26
internal/repository/milestone/type.go
Normal file
26
internal/repository/milestone/type.go
Normal file
@@ -0,0 +1,26 @@
|
||||
//go:generate stringer -type Type
|
||||
|
||||
package milestone
|
||||
|
||||
type Type int
|
||||
|
||||
const (
|
||||
unknown Type = iota
|
||||
|
||||
InstanceCreated
|
||||
AuthenticationSucceededOnInstance
|
||||
ProjectCreated
|
||||
ApplicationCreated
|
||||
AuthenticationSucceededOnApplication
|
||||
InstanceDeleted
|
||||
|
||||
typesCount
|
||||
)
|
||||
|
||||
func AllTypes() []Type {
|
||||
types := make([]Type, typesCount-1)
|
||||
for i := Type(1); i < typesCount; i++ {
|
||||
types[i-1] = i
|
||||
}
|
||||
return types
|
||||
}
|
||||
30
internal/repository/milestone/type_string.go
Normal file
30
internal/repository/milestone/type_string.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// Code generated by "stringer -type Type"; DO NOT EDIT.
|
||||
|
||||
package milestone
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[unknown-0]
|
||||
_ = x[InstanceCreated-1]
|
||||
_ = x[AuthenticationSucceededOnInstance-2]
|
||||
_ = x[ProjectCreated-3]
|
||||
_ = x[ApplicationCreated-4]
|
||||
_ = x[AuthenticationSucceededOnApplication-5]
|
||||
_ = x[InstanceDeleted-6]
|
||||
_ = x[typesCount-7]
|
||||
}
|
||||
|
||||
const _Type_name = "unknownInstanceCreatedAuthenticationSucceededOnInstanceProjectCreatedApplicationCreatedAuthenticationSucceededOnApplicationInstanceDeletedtypesCount"
|
||||
|
||||
var _Type_index = [...]uint8{0, 7, 22, 55, 69, 87, 123, 138, 148}
|
||||
|
||||
func (i Type) String() string {
|
||||
if i < 0 || i >= Type(len(_Type_index)-1) {
|
||||
return "Type(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Type_name[_Type_index[i]:_Type_index[i+1]]
|
||||
}
|
||||
Reference in New Issue
Block a user