mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
c9e2e6bc33
* fix(metadata): corrected handling of remove metadata events * remove unnecessary method Co-authored-by: Livio Spring <livio.a@gmail.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package command
|
|
|
|
import (
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/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:
|
|
if wm.Key != e.Key {
|
|
continue
|
|
}
|
|
wm.State = domain.MetadataStateRemoved
|
|
case *metadata.RemovedAllEvent:
|
|
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)
|
|
case *metadata.RemovedAllEvent:
|
|
wm.metadataList = make(map[string][]byte)
|
|
}
|
|
}
|
|
return wm.WriteModel.Reduce()
|
|
}
|