67 lines
1.5 KiB
Go
Raw Normal View History

2023-06-21 11:40:16 +02:00
//go:
2023-06-19 12:15:30 +02:00
package milestone
import (
"context"
"encoding/json"
2023-06-21 11:40:16 +02:00
"time"
2023-06-19 12:15:30 +02:00
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
)
const (
2023-06-21 11:40:16 +02:00
eventTypePrefix = eventstore.EventType("milestone.")
PushedEventType = eventTypePrefix + "pushed"
2023-06-19 12:15:30 +02:00
)
type PushedEvent struct {
eventstore.BaseEvent `json:"-"`
2023-06-21 11:40:16 +02:00
Milestone Milestone `json:"milestone"`
Reached time.Time `json:"reached"`
Endpoints []string `json:"endpoints"`
PrimaryDomain string `json:"primaryDomain"`
2023-06-19 12:15:30 +02:00
}
func (e *PushedEvent) Data() interface{} {
return e
}
func (e *PushedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewPushedEvent(
ctx context.Context,
2023-06-21 11:40:16 +02:00
newAggregate *Aggregate,
milestone Milestone,
reached time.Time,
2023-06-19 12:15:30 +02:00
endpoints []string,
2023-06-21 11:40:16 +02:00
primaryDomain string,
2023-06-19 12:15:30 +02:00
) *PushedEvent {
return &PushedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
2023-06-21 11:40:16 +02:00
&newAggregate.Aggregate,
2023-06-19 12:15:30 +02:00
PushedEventType,
),
2023-06-21 11:40:16 +02:00
Milestone: milestone,
Reached: reached,
Endpoints: endpoints,
PrimaryDomain: primaryDomain,
2023-06-19 12:15:30 +02:00
}
}
func PushedEventMapper(event *repository.Event) (eventstore.Event, error) {
e := &PushedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "QUOTA-4n8vs", "unable to unmarshal milestone pushed")
}
return e, nil
}