zitadel/internal/repository/iam/member.go
Fabi d8e42744b4
fix: move v2 pkgs (#1331)
* fix: move eventstore pkgs

* fix: move eventstore pkgs

* fix: remove v2 view

* fix: remove v2 view
2021-02-23 15:13:04 +01:00

112 lines
2.3 KiB
Go

package iam
import (
"context"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/repository"
"github.com/caos/zitadel/internal/repository/member"
)
var (
MemberAddedEventType = iamEventTypePrefix + member.AddedEventType
MemberChangedEventType = iamEventTypePrefix + member.ChangedEventType
MemberRemovedEventType = iamEventTypePrefix + member.RemovedEventType
)
type MemberAddedEvent struct {
member.MemberAddedEvent
}
func NewMemberAddedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
roles ...string,
) *MemberAddedEvent {
return &MemberAddedEvent{
MemberAddedEvent: *member.NewMemberAddedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
MemberAddedEventType,
),
userID,
roles...,
),
}
}
func MemberAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := member.MemberAddedEventMapper(event)
if err != nil {
return nil, err
}
return &MemberAddedEvent{MemberAddedEvent: *e.(*member.MemberAddedEvent)}, nil
}
type MemberChangedEvent struct {
member.MemberChangedEvent
}
func NewMemberChangedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
roles ...string,
) *MemberChangedEvent {
return &MemberChangedEvent{
MemberChangedEvent: *member.NewMemberChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
MemberChangedEventType,
),
userID,
roles...,
),
}
}
func MemberChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := member.ChangedEventMapper(event)
if err != nil {
return nil, err
}
return &MemberChangedEvent{MemberChangedEvent: *e.(*member.MemberChangedEvent)}, nil
}
type MemberRemovedEvent struct {
member.MemberRemovedEvent
}
func NewMemberRemovedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
) *MemberRemovedEvent {
return &MemberRemovedEvent{
MemberRemovedEvent: *member.NewRemovedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
MemberRemovedEventType,
),
userID,
),
}
}
func MemberRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := member.RemovedEventMapper(event)
if err != nil {
return nil, err
}
return &MemberRemovedEvent{MemberRemovedEvent: *e.(*member.MemberRemovedEvent)}, nil
}