mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
28 lines
766 B
Go
28 lines
766 B
Go
package sdk
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
)
|
|
|
|
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)
|
|
|
|
func Filter(ctx context.Context, filter filterFunc, appender appendFunc, query *es_models.SearchQuery) error {
|
|
events, err := filter(ctx, query)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(events) == 0 {
|
|
return errors.ThrowNotFound(nil, "EVENT-8due3", "no events found")
|
|
}
|
|
err = appender(events...)
|
|
if err != nil {
|
|
return ThrowAppendEventError(err, "SDK-awiWK", "Errors.Internal")
|
|
}
|
|
return nil
|
|
}
|