mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34: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>
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package command
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/repository/metadata"
|
|
)
|
|
|
|
type MetadataWriteModel struct {
|
|
eventstore.WriteModel
|
|
|
|
Key string
|
|
Value []byte
|
|
State domain.MetadataState
|
|
}
|
|
|
|
func (wm *MetadataWriteModel) Reduce() error {
|
|
for _, event := range wm.Events {
|
|
switch e := event.(type) {
|
|
case *metadata.SetEvent:
|
|
if wm.Key != e.Key {
|
|
continue
|
|
}
|
|
wm.Value = e.Value
|
|
wm.State = domain.MetadataStateActive
|
|
case *metadata.RemovedEvent:
|
|
wm.State = domain.MetadataStateRemoved
|
|
}
|
|
}
|
|
return wm.WriteModel.Reduce()
|
|
}
|
|
|
|
type MetadataListWriteModel struct {
|
|
eventstore.WriteModel
|
|
|
|
metadataList map[string][]byte
|
|
}
|
|
|
|
func (wm *MetadataListWriteModel) Reduce() error {
|
|
for _, event := range wm.Events {
|
|
switch e := event.(type) {
|
|
case *metadata.SetEvent:
|
|
wm.metadataList[e.Key] = e.Value
|
|
case *metadata.RemovedEvent:
|
|
delete(wm.metadataList, e.Key)
|
|
}
|
|
}
|
|
return wm.WriteModel.Reduce()
|
|
}
|