2023-07-06 06:38:13 +00:00
|
|
|
package milestone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-10-28 08:29:34 +00:00
|
|
|
"time"
|
2023-07-06 06:38:13 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
2024-11-11 11:28:27 +00:00
|
|
|
//go:generate enumer -type Type -json -linecomment
|
2024-10-28 08:29:34 +00:00
|
|
|
type Type int
|
|
|
|
|
2023-07-06 06:38:13 +00:00
|
|
|
const (
|
2024-10-31 11:03:40 +00:00
|
|
|
InstanceCreated Type = iota + 1
|
2024-10-28 08:29:34 +00:00
|
|
|
AuthenticationSucceededOnInstance
|
|
|
|
ProjectCreated
|
|
|
|
ApplicationCreated
|
|
|
|
AuthenticationSucceededOnApplication
|
|
|
|
InstanceDeleted
|
2023-07-06 06:38:13 +00:00
|
|
|
)
|
|
|
|
|
2024-10-28 08:29:34 +00:00
|
|
|
const (
|
2024-11-11 11:28:27 +00:00
|
|
|
eventTypePrefix = "milestone.v2."
|
2024-10-28 08:29:34 +00:00
|
|
|
ReachedEventType = eventTypePrefix + "reached"
|
|
|
|
PushedEventType = eventTypePrefix + "pushed"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ReachedEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
MilestoneType Type `json:"type"`
|
|
|
|
ReachedDate *time.Time `json:"reachedDate,omitempty"` // Defaults to [eventstore.BaseEvent.Creation] when empty
|
|
|
|
}
|
|
|
|
|
|
|
|
// Payload implements eventstore.Command.
|
|
|
|
func (e *ReachedEvent) Payload() any {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ReachedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ReachedEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ReachedEvent) GetReachedDate() time.Time {
|
|
|
|
if e.ReachedDate != nil {
|
|
|
|
return *e.ReachedDate
|
|
|
|
}
|
|
|
|
return e.Creation
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewReachedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *Aggregate,
|
|
|
|
typ Type,
|
|
|
|
) *ReachedEvent {
|
|
|
|
return NewReachedEventWithDate(ctx, aggregate, typ, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewReachedEventWithDate creates a [ReachedEvent] with a fixed Reached Date.
|
|
|
|
func NewReachedEventWithDate(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *Aggregate,
|
|
|
|
typ Type,
|
|
|
|
reachedDate *time.Time,
|
|
|
|
) *ReachedEvent {
|
|
|
|
return &ReachedEvent{
|
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
&aggregate.Aggregate,
|
|
|
|
ReachedEventType,
|
|
|
|
),
|
|
|
|
MilestoneType: typ,
|
|
|
|
ReachedDate: reachedDate,
|
|
|
|
}
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
|
2023-07-06 06:38:13 +00:00
|
|
|
type PushedEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2024-10-28 08:29:34 +00:00
|
|
|
MilestoneType Type `json:"type"`
|
|
|
|
ExternalDomain string `json:"externalDomain"`
|
|
|
|
PrimaryDomain string `json:"primaryDomain"`
|
|
|
|
Endpoints []string `json:"endpoints"`
|
|
|
|
PushedDate *time.Time `json:"pushedDate,omitempty"` // Defaults to [eventstore.BaseEvent.Creation] when empty
|
2023-07-06 06:38:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
// Payload implements eventstore.Command.
|
|
|
|
func (p *PushedEvent) Payload() any {
|
2023-07-06 06:38:13 +00:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (p *PushedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-07-06 06:38:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PushedEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
p.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
2024-10-28 08:29:34 +00:00
|
|
|
func (e *PushedEvent) GetPushedDate() time.Time {
|
|
|
|
if e.PushedDate != nil {
|
|
|
|
return *e.PushedDate
|
|
|
|
}
|
|
|
|
return e.Creation
|
|
|
|
}
|
2023-07-06 06:38:13 +00:00
|
|
|
|
|
|
|
func NewPushedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *Aggregate,
|
2024-10-28 08:29:34 +00:00
|
|
|
typ Type,
|
|
|
|
endpoints []string,
|
|
|
|
externalDomain string,
|
|
|
|
) *PushedEvent {
|
|
|
|
return NewPushedEventWithDate(ctx, aggregate, typ, endpoints, externalDomain, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPushedEventWithDate creates a [PushedEvent] with a fixed Pushed Date.
|
|
|
|
func NewPushedEventWithDate(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *Aggregate,
|
|
|
|
typ Type,
|
2023-07-06 06:38:13 +00:00
|
|
|
endpoints []string,
|
2024-10-28 08:29:34 +00:00
|
|
|
externalDomain string,
|
|
|
|
pushedDate *time.Time,
|
2023-07-06 06:38:13 +00:00
|
|
|
) *PushedEvent {
|
|
|
|
return &PushedEvent{
|
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
&aggregate.Aggregate,
|
|
|
|
PushedEventType,
|
|
|
|
),
|
2024-10-28 08:29:34 +00:00
|
|
|
MilestoneType: typ,
|
2023-07-06 06:38:13 +00:00
|
|
|
Endpoints: endpoints,
|
|
|
|
ExternalDomain: externalDomain,
|
2024-10-28 08:29:34 +00:00
|
|
|
PushedDate: pushedDate,
|
2023-07-06 06:38:13 +00:00
|
|
|
}
|
|
|
|
}
|