mirror of
https://github.com/zitadel/zitadel.git
synced 2025-11-15 23:03:30 +00:00
feat: pub sub (#1341)
* fix: pub sub * fix: adaot config to commands (and queries) * remove dependency on vv2 in v1 * fix: pub sub in new eventstore * fix tests Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
type filterFunc func(context.Context, *es_models.SearchQuery) ([]*es_models.Event, error)
|
||||
type appendFunc func(...*es_models.Event) error
|
||||
type AggregateFunc func(context.Context) (*es_models.Aggregate, error)
|
||||
type pushFunc func(context.Context, ...*es_models.Aggregate) error
|
||||
|
||||
func Filter(ctx context.Context, filter filterFunc, appender appendFunc, query *es_models.SearchQuery) error {
|
||||
events, err := filter(ctx, query)
|
||||
@@ -26,62 +25,3 @@ func Filter(ctx context.Context, filter filterFunc, appender appendFunc, query *
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Push is Deprecated use PushAggregates
|
||||
// Push creates the aggregates from aggregater
|
||||
// and pushes the aggregates to the given pushFunc
|
||||
// the given events are appended by the appender
|
||||
func Push(ctx context.Context, push pushFunc, appender appendFunc, aggregaters ...AggregateFunc) (err error) {
|
||||
if len(aggregaters) < 1 {
|
||||
return errors.ThrowPreconditionFailed(nil, "SDK-q9wjp", "Errors.Internal")
|
||||
}
|
||||
|
||||
aggregates, err := makeAggregates(ctx, aggregaters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = push(ctx, aggregates...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return appendAggregates(appender, aggregates)
|
||||
}
|
||||
|
||||
func PushAggregates(ctx context.Context, push pushFunc, appender appendFunc, aggregates ...*es_models.Aggregate) (err error) {
|
||||
if len(aggregates) < 1 {
|
||||
return errors.ThrowPreconditionFailed(nil, "SDK-q9wjp", "Errors.Internal")
|
||||
}
|
||||
|
||||
err = push(ctx, aggregates...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if appender == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return appendAggregates(appender, aggregates)
|
||||
}
|
||||
|
||||
func appendAggregates(appender appendFunc, aggregates []*es_models.Aggregate) error {
|
||||
for _, aggregate := range aggregates {
|
||||
err := appender(aggregate.Events...)
|
||||
if err != nil {
|
||||
return ThrowAppendEventError(err, "SDK-o6kzK", "Errors.Internal")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeAggregates(ctx context.Context, aggregaters []AggregateFunc) (aggregates []*es_models.Aggregate, err error) {
|
||||
aggregates = make([]*es_models.Aggregate, len(aggregaters))
|
||||
for i, aggregater := range aggregaters {
|
||||
aggregates[i], err = aggregater(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return aggregates, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user