feat(instance): add functionality to update instance (#4440)

Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com>
This commit is contained in:
Stefan Benz
2022-09-27 07:58:50 +01:00
committed by GitHub
parent 0755ed8a70
commit b32c02a39b
16 changed files with 339 additions and 5 deletions

View File

@@ -62,6 +62,10 @@ func (p *instanceProjection) reducers() []handler.AggregateReducer {
Event: instance.InstanceAddedEventType,
Reduce: p.reduceInstanceAdded,
},
{
Event: instance.InstanceChangedEventType,
Reduce: p.reduceInstanceChanged,
},
{
Event: instance.DefaultOrgSetEventType,
Reduce: p.reduceDefaultOrgSet,
@@ -100,6 +104,24 @@ func (p *instanceProjection) reduceInstanceAdded(event eventstore.Event) (*handl
), nil
}
func (p *instanceProjection) reduceInstanceChanged(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.InstanceChangedEvent)
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-so2am1", "reduce.wrong.event.type %s", instance.InstanceChangedEventType)
}
return crdb.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(InstanceColumnName, e.Name),
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
handler.NewCol(InstanceColumnSequence, e.Sequence()),
},
[]handler.Condition{
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
},
), nil
}
func (p *instanceProjection) reduceDefaultOrgSet(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.DefaultOrgSetEvent)
if !ok {