zitadel/internal/v2/repository/member/event_added.go

55 lines
1001 B
Go
Raw Normal View History

2020-11-06 12:47:27 +00:00
package member
import (
"encoding/json"
"github.com/caos/zitadel/internal/errors"
2020-11-06 12:47:27 +00:00
"github.com/caos/zitadel/internal/eventstore/v2"
2020-11-25 19:04:32 +00:00
es_repo "github.com/caos/zitadel/internal/eventstore/v2/repository"
2020-11-06 12:47:27 +00:00
)
2020-11-11 16:51:44 +00:00
const (
AddedEventType = "member.added"
)
type AddedEvent struct {
2020-11-06 12:47:27 +00:00
eventstore.BaseEvent `json:"-"`
Roles []string `json:"roles"`
UserID string `json:"userId"`
}
2020-11-11 16:51:44 +00:00
func (e *AddedEvent) CheckPrevious() bool {
2020-11-06 12:47:27 +00:00
return true
}
2020-11-11 16:51:44 +00:00
func (e *AddedEvent) Data() interface{} {
2020-11-06 12:47:27 +00:00
return e
}
2020-11-06 16:25:07 +00:00
func NewAddedEvent(
2020-11-11 16:51:44 +00:00
base *eventstore.BaseEvent,
2020-11-06 21:09:19 +00:00
userID string,
roles ...string,
2020-11-11 16:51:44 +00:00
) *AddedEvent {
return &AddedEvent{
BaseEvent: *base,
Roles: roles,
UserID: userID,
2020-11-06 16:25:07 +00:00
}
}
2020-11-25 19:04:32 +00:00
func AddedEventMapper(event *es_repo.Event) (eventstore.EventReader, error) {
e := &AddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "POLIC-puqv4", "unable to unmarshal label policy")
}
return e, nil
}