2021-01-12 11:59:51 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/project"
|
2021-01-12 11:59:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ProjectMemberWriteModel struct {
|
|
|
|
MemberWriteModel
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProjectMemberWriteModel(projectID, userID, resourceOwner string) *ProjectMemberWriteModel {
|
|
|
|
return &ProjectMemberWriteModel{
|
|
|
|
MemberWriteModel{
|
|
|
|
WriteModel: eventstore.WriteModel{
|
|
|
|
AggregateID: projectID,
|
|
|
|
ResourceOwner: resourceOwner,
|
|
|
|
},
|
|
|
|
UserID: userID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *ProjectMemberWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
|
|
for _, event := range events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *project.MemberAddedEvent:
|
|
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberAddedEvent)
|
|
|
|
case *project.MemberChangedEvent:
|
|
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberChangedEvent)
|
|
|
|
case *project.MemberRemovedEvent:
|
|
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberRemovedEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *ProjectMemberWriteModel) Reduce() error {
|
|
|
|
return wm.MemberWriteModel.Reduce()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *ProjectMemberWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, project.AggregateType).
|
|
|
|
AggregateIDs(wm.MemberWriteModel.AggregateID).
|
2021-02-18 13:48:27 +00:00
|
|
|
ResourceOwner(wm.ResourceOwner).
|
|
|
|
EventTypes(project.MemberAddedType,
|
|
|
|
project.MemberChangedType,
|
|
|
|
project.MemberRemovedType)
|
2021-01-12 11:59:51 +00:00
|
|
|
}
|