zitadel/internal/repository/instance/member.go

143 lines
3.1 KiB
Go
Raw Normal View History

package instance
2020-11-11 16:51:44 +00:00
import (
"context"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/repository"
"github.com/caos/zitadel/internal/repository/member"
2020-11-11 16:51:44 +00:00
)
var (
MemberAddedEventType = instanceEventTypePrefix + member.AddedEventType
MemberChangedEventType = instanceEventTypePrefix + member.ChangedEventType
MemberRemovedEventType = instanceEventTypePrefix + member.RemovedEventType
MemberCascadeRemovedEventType = instanceEventTypePrefix + member.CascadeRemovedEventType
2020-11-11 16:51:44 +00:00
)
type MemberAddedEvent struct {
member.MemberAddedEvent
2020-11-11 16:51:44 +00:00
}
func NewMemberAddedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
2020-11-11 16:51:44 +00:00
userID string,
roles ...string,
) *MemberAddedEvent {
return &MemberAddedEvent{
MemberAddedEvent: *member.NewMemberAddedEvent(
2020-11-11 16:51:44 +00:00
eventstore.NewBaseEventForPush(
ctx,
aggregate,
2020-11-11 16:51:44 +00:00
MemberAddedEventType,
),
userID,
roles...,
),
}
}
func MemberAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := member.MemberAddedEventMapper(event)
if err != nil {
return nil, err
}
return &MemberAddedEvent{MemberAddedEvent: *e.(*member.MemberAddedEvent)}, nil
}
2020-11-25 13:12:44 +00:00
type MemberChangedEvent struct {
member.MemberChangedEvent
2020-11-25 13:12:44 +00:00
}
func NewMemberChangedEvent(
2020-11-11 16:51:44 +00:00
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
2020-11-23 18:31:12 +00:00
roles ...string,
) *MemberChangedEvent {
return &MemberChangedEvent{
MemberChangedEvent: *member.NewMemberChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
MemberChangedEventType,
),
userID,
roles...,
2020-11-11 16:51:44 +00:00
),
}
}
func MemberChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := member.ChangedEventMapper(event)
if err != nil {
return nil, err
2020-11-23 18:31:12 +00:00
}
return &MemberChangedEvent{MemberChangedEvent: *e.(*member.MemberChangedEvent)}, nil
2020-11-23 18:31:12 +00:00
}
2020-11-25 13:12:44 +00:00
type MemberRemovedEvent struct {
member.MemberRemovedEvent
2020-11-25 13:12:44 +00:00
}
2020-11-11 16:51:44 +00:00
func NewMemberRemovedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
2020-11-11 16:51:44 +00:00
userID string,
) *MemberRemovedEvent {
return &MemberRemovedEvent{
MemberRemovedEvent: *member.NewRemovedEvent(
2020-11-11 16:51:44 +00:00
eventstore.NewBaseEventForPush(
ctx,
aggregate,
2020-11-11 16:51:44 +00:00
MemberRemovedEventType,
),
userID,
),
}
}
func MemberRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := member.RemovedEventMapper(event)
if err != nil {
return nil, err
}
return &MemberRemovedEvent{MemberRemovedEvent: *e.(*member.MemberRemovedEvent)}, nil
}
type MemberCascadeRemovedEvent struct {
member.MemberCascadeRemovedEvent
}
func NewMemberCascadeRemovedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
) *MemberCascadeRemovedEvent {
return &MemberCascadeRemovedEvent{
MemberCascadeRemovedEvent: *member.NewCascadeRemovedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
MemberCascadeRemovedEventType,
),
userID,
),
}
}
func MemberCascadeRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := member.CascadeRemovedEventMapper(event)
if err != nil {
return nil, err
}
return &MemberCascadeRemovedEvent{MemberCascadeRemovedEvent: *e.(*member.MemberCascadeRemovedEvent)}, nil
}