mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
7451ed58f2
* feat: user meta data events * feat: user meta data set tests * feat: user meta data tests * feat: user meta data in protos * feat: user meta data command api * feat: user meta data query side * feat: proto correct order, fix handlers * feat: proto correct order * feat: fixes of pr comments * feat: fixes of pr comments * feat: value as byte array * feat: metadata feature * Update internal/auth/repository/eventsourcing/handler/meta_data.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/command/user_meta_data.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update proto/zitadel/metadata.proto Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update proto/zitadel/metadata.proto Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: rename metadata files and table * fix: rename meta data to metadat in protos * Update internal/domain/metadata.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: rename vars * fix: rebiuld docs * Update internal/iam/repository/view/metadata_view.go Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Silvan <silvan.reusser@gmail.com>
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
package command
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/repository/user"
|
|
)
|
|
|
|
type UserMetadataWriteModel struct {
|
|
MetadataWriteModel
|
|
}
|
|
|
|
func NewUserMetadataWriteModel(userID, resourceOwner, key string) *UserMetadataWriteModel {
|
|
return &UserMetadataWriteModel{
|
|
MetadataWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: userID,
|
|
ResourceOwner: resourceOwner,
|
|
},
|
|
Key: key,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *UserMetadataWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *user.MetadataSetEvent:
|
|
wm.MetadataWriteModel.AppendEvents(&e.SetEvent)
|
|
case *user.MetadataRemovedEvent:
|
|
wm.MetadataWriteModel.AppendEvents(&e.RemovedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *UserMetadataWriteModel) Reduce() error {
|
|
return wm.MetadataWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *UserMetadataWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
AddQuery().
|
|
AggregateIDs(wm.MetadataWriteModel.AggregateID).
|
|
AggregateTypes(user.AggregateType).
|
|
EventTypes(
|
|
user.MetadataSetType,
|
|
user.MetadataRemovedType).
|
|
Builder()
|
|
}
|
|
|
|
type UserMetadataListWriteModel struct {
|
|
MetadataListWriteModel
|
|
}
|
|
|
|
func NewUserMetadataListWriteModel(userID, resourceOwner string) *UserMetadataListWriteModel {
|
|
return &UserMetadataListWriteModel{
|
|
MetadataListWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: userID,
|
|
ResourceOwner: resourceOwner,
|
|
},
|
|
metadataList: make(map[string][]byte),
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *UserMetadataListWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *user.MetadataSetEvent:
|
|
wm.MetadataListWriteModel.AppendEvents(&e.SetEvent)
|
|
case *user.MetadataRemovedEvent:
|
|
wm.MetadataListWriteModel.AppendEvents(&e.RemovedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *UserMetadataListWriteModel) Reduce() error {
|
|
return wm.MetadataListWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *UserMetadataListWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
AddQuery().
|
|
AggregateIDs(wm.MetadataListWriteModel.AggregateID).
|
|
AggregateTypes(user.AggregateType).
|
|
EventTypes(
|
|
user.MetadataSetType,
|
|
user.MetadataRemovedType).
|
|
Builder()
|
|
}
|