mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
facotry to fileter
This commit is contained in:
parent
cf1df99a10
commit
9a870b7830
@ -93,7 +93,7 @@ func (es *Eventstore) aggregatesToEvents(aggregates []aggregater) ([]*repository
|
||||
|
||||
//FilterEvents filters the stored events based on the searchQuery
|
||||
// and maps the events to the defined event structs
|
||||
func (es *Eventstore) FilterEvents(ctx context.Context, queryFactory *SearchQueryFactory) ([]EventReader, error) {
|
||||
func (es *Eventstore) FilterEvents(ctx context.Context, queryFactory *SearchQueryBuilder) ([]EventReader, error) {
|
||||
query, err := queryFactory.build()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -138,7 +138,7 @@ type reducer interface {
|
||||
}
|
||||
|
||||
//FilterToReducer filters the events based on the search query, appends all events to the reducer and calls it's reduce function
|
||||
func (es *Eventstore) FilterToReducer(ctx context.Context, searchQuery *SearchQueryFactory, r reducer) error {
|
||||
func (es *Eventstore) FilterToReducer(ctx context.Context, searchQuery *SearchQueryBuilder, r reducer) error {
|
||||
events, err := es.FilterEvents(ctx, searchQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -150,7 +150,7 @@ func (es *Eventstore) FilterToReducer(ctx context.Context, searchQuery *SearchQu
|
||||
}
|
||||
|
||||
//LatestSequence filters the latest sequence for the given search query
|
||||
func (es *Eventstore) LatestSequence(ctx context.Context, queryFactory *SearchQueryFactory) (uint64, error) {
|
||||
func (es *Eventstore) LatestSequence(ctx context.Context, queryFactory *SearchQueryBuilder) (uint64, error) {
|
||||
query, err := queryFactory.build()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -161,7 +161,7 @@ func (es *Eventstore) LatestSequence(ctx context.Context, queryFactory *SearchQu
|
||||
type queryReducer interface {
|
||||
reducer
|
||||
//Query returns the SearchQueryFactory for the events needed in reducer
|
||||
Query() *SearchQueryFactory
|
||||
Query() *SearchQueryBuilder
|
||||
}
|
||||
|
||||
//FilterToQueryReducer filters the events based on the search query of the query function,
|
||||
|
@ -908,7 +908,7 @@ func TestEventstore_Push(t *testing.T) {
|
||||
|
||||
func TestEventstore_FilterEvents(t *testing.T) {
|
||||
type args struct {
|
||||
query *SearchQueryFactory
|
||||
query *SearchQueryBuilder
|
||||
}
|
||||
type fields struct {
|
||||
repo *testRepo
|
||||
@ -935,7 +935,7 @@ func TestEventstore_FilterEvents(t *testing.T) {
|
||||
{
|
||||
name: "no events",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"no.aggregates"},
|
||||
columns: repository.ColumnsEvent,
|
||||
},
|
||||
@ -958,7 +958,7 @@ func TestEventstore_FilterEvents(t *testing.T) {
|
||||
{
|
||||
name: "repo error",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"no.aggregates"},
|
||||
columns: repository.ColumnsEvent,
|
||||
},
|
||||
@ -981,7 +981,7 @@ func TestEventstore_FilterEvents(t *testing.T) {
|
||||
{
|
||||
name: "found events",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"test.aggregate"},
|
||||
columns: repository.ColumnsEvent,
|
||||
},
|
||||
@ -1033,7 +1033,7 @@ func TestEventstore_FilterEvents(t *testing.T) {
|
||||
|
||||
func TestEventstore_LatestSequence(t *testing.T) {
|
||||
type args struct {
|
||||
query *SearchQueryFactory
|
||||
query *SearchQueryBuilder
|
||||
}
|
||||
type fields struct {
|
||||
repo *testRepo
|
||||
@ -1059,7 +1059,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
|
||||
{
|
||||
name: "no events",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"no.aggregates"},
|
||||
columns: repository.ColumnsMaxSequence,
|
||||
},
|
||||
@ -1077,7 +1077,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
|
||||
{
|
||||
name: "repo error",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"no.aggregates"},
|
||||
columns: repository.ColumnsMaxSequence,
|
||||
},
|
||||
@ -1095,7 +1095,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
|
||||
{
|
||||
name: "found events",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"test.aggregate"},
|
||||
columns: repository.ColumnsMaxSequence,
|
||||
},
|
||||
@ -1149,7 +1149,7 @@ func (r *testReducer) AppendEvents(e ...EventReader) {
|
||||
|
||||
func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
type args struct {
|
||||
query *SearchQueryFactory
|
||||
query *SearchQueryBuilder
|
||||
readModel reducer
|
||||
}
|
||||
type fields struct {
|
||||
@ -1177,7 +1177,7 @@ func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
{
|
||||
name: "no events",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"no.aggregates"},
|
||||
columns: repository.ColumnsEvent,
|
||||
},
|
||||
@ -1204,7 +1204,7 @@ func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
{
|
||||
name: "repo error",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"no.aggregates"},
|
||||
columns: repository.ColumnsEvent,
|
||||
},
|
||||
@ -1231,7 +1231,7 @@ func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
{
|
||||
name: "found events",
|
||||
args: args{
|
||||
query: NewSearchQueryFactory(repository.ColumnsEvent, "test.aggregate"),
|
||||
query: NewSearchQueryBuilder(repository.ColumnsEvent, "test.aggregate"),
|
||||
readModel: &testReducer{
|
||||
t: t,
|
||||
expectedLength: 1,
|
||||
@ -1257,7 +1257,7 @@ func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
{
|
||||
name: "append in reducer fails",
|
||||
args: args{
|
||||
query: &SearchQueryFactory{
|
||||
query: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"test.aggregate"},
|
||||
columns: repository.ColumnsEvent,
|
||||
},
|
||||
|
@ -317,7 +317,7 @@ func TestUserReadModel(t *testing.T) {
|
||||
fmt.Printf("%+v\n", events)
|
||||
|
||||
users := UsersReadModel{}
|
||||
err = es.FilterToReducer(context.Background(), eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, "test.user"), &users)
|
||||
err = es.FilterToReducer(context.Background(), eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, "test.user"), &users)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error on filter to reducer: %v", err)
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
)
|
||||
|
||||
//SearchQueryFactory represents the builder for your filter
|
||||
//SearchQueryBuilder represents the builder for your filter
|
||||
// if invalid data are set the filter will fail
|
||||
type SearchQueryFactory struct {
|
||||
type SearchQueryBuilder struct {
|
||||
columns repository.Columns
|
||||
limit uint64
|
||||
desc bool
|
||||
@ -35,61 +35,61 @@ type AggregateType repository.AggregateType
|
||||
// EventType is the description of the change
|
||||
type EventType repository.EventType
|
||||
|
||||
// NewSearchQueryFactory creates a new factory for event filters
|
||||
// NewSearchQueryBuilder creates a new factory for event filters
|
||||
// aggregateTypes must contain at least one aggregate type
|
||||
func NewSearchQueryFactory(columns Columns, aggregateTypes ...AggregateType) *SearchQueryFactory {
|
||||
return &SearchQueryFactory{
|
||||
func NewSearchQueryBuilder(columns Columns, aggregateTypes ...AggregateType) *SearchQueryBuilder {
|
||||
return &SearchQueryBuilder{
|
||||
columns: repository.Columns(columns),
|
||||
aggregateTypes: aggregateTypes,
|
||||
}
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) Columns(columns Columns) *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) Columns(columns Columns) *SearchQueryBuilder {
|
||||
factory.columns = repository.Columns(columns)
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) Limit(limit uint64) *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) Limit(limit uint64) *SearchQueryBuilder {
|
||||
factory.limit = limit
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) SequenceGreater(sequence uint64) *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) SequenceGreater(sequence uint64) *SearchQueryBuilder {
|
||||
factory.eventSequence = sequence
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) AggregateIDs(ids ...string) *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) AggregateIDs(ids ...string) *SearchQueryBuilder {
|
||||
factory.aggregateIDs = ids
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) EventTypes(types ...EventType) *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) EventTypes(types ...EventType) *SearchQueryBuilder {
|
||||
factory.eventTypes = types
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) ResourceOwner(resourceOwner string) *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) ResourceOwner(resourceOwner string) *SearchQueryBuilder {
|
||||
factory.resourceOwner = resourceOwner
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) OrderDesc() *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) OrderDesc() *SearchQueryBuilder {
|
||||
factory.desc = true
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) OrderAsc() *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) OrderAsc() *SearchQueryBuilder {
|
||||
factory.desc = false
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) EventData(query map[string]interface{}) *SearchQueryFactory {
|
||||
func (factory *SearchQueryBuilder) EventData(query map[string]interface{}) *SearchQueryBuilder {
|
||||
factory.eventData = query
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) build() (*repository.SearchQuery, error) {
|
||||
func (factory *SearchQueryBuilder) build() (*repository.SearchQuery, error) {
|
||||
if factory == nil ||
|
||||
len(factory.aggregateTypes) < 1 ||
|
||||
factory.columns.Validate() != nil {
|
||||
@ -122,7 +122,7 @@ func (factory *SearchQueryFactory) build() (*repository.SearchQuery, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) aggregateIDFilter() *repository.Filter {
|
||||
func (factory *SearchQueryBuilder) aggregateIDFilter() *repository.Filter {
|
||||
if len(factory.aggregateIDs) < 1 {
|
||||
return nil
|
||||
}
|
||||
@ -132,7 +132,7 @@ func (factory *SearchQueryFactory) aggregateIDFilter() *repository.Filter {
|
||||
return repository.NewFilter(repository.FieldAggregateID, factory.aggregateIDs, repository.OperationIn)
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) eventTypeFilter() *repository.Filter {
|
||||
func (factory *SearchQueryBuilder) eventTypeFilter() *repository.Filter {
|
||||
if len(factory.eventTypes) < 1 {
|
||||
return nil
|
||||
}
|
||||
@ -142,14 +142,14 @@ func (factory *SearchQueryFactory) eventTypeFilter() *repository.Filter {
|
||||
return repository.NewFilter(repository.FieldEventType, factory.eventTypes, repository.OperationIn)
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) aggregateTypeFilter() *repository.Filter {
|
||||
func (factory *SearchQueryBuilder) aggregateTypeFilter() *repository.Filter {
|
||||
if len(factory.aggregateTypes) == 1 {
|
||||
return repository.NewFilter(repository.FieldAggregateType, factory.aggregateTypes[0], repository.OperationEquals)
|
||||
}
|
||||
return repository.NewFilter(repository.FieldAggregateType, factory.aggregateTypes, repository.OperationIn)
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) eventSequenceFilter() *repository.Filter {
|
||||
func (factory *SearchQueryBuilder) eventSequenceFilter() *repository.Filter {
|
||||
if factory.eventSequence == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -160,14 +160,14 @@ func (factory *SearchQueryFactory) eventSequenceFilter() *repository.Filter {
|
||||
return repository.NewFilter(repository.FieldSequence, factory.eventSequence, sortOrder)
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) resourceOwnerFilter() *repository.Filter {
|
||||
func (factory *SearchQueryBuilder) resourceOwnerFilter() *repository.Filter {
|
||||
if factory.resourceOwner == "" {
|
||||
return nil
|
||||
}
|
||||
return repository.NewFilter(repository.FieldResourceOwner, factory.resourceOwner, repository.OperationEquals)
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) eventDataFilter() *repository.Filter {
|
||||
func (factory *SearchQueryBuilder) eventDataFilter() *repository.Filter {
|
||||
if len(factory.eventData) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -9,50 +9,50 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
)
|
||||
|
||||
func testSetColumns(columns Columns) func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
return func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
func testSetColumns(columns Columns) func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
return func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
factory = factory.Columns(columns)
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
func testSetLimit(limit uint64) func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
return func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
func testSetLimit(limit uint64) func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
return func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
factory = factory.Limit(limit)
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
func testSetSequence(sequence uint64) func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
return func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
func testSetSequence(sequence uint64) func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
return func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
factory = factory.SequenceGreater(sequence)
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
func testSetAggregateIDs(aggregateIDs ...string) func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
return func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
func testSetAggregateIDs(aggregateIDs ...string) func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
return func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
factory = factory.AggregateIDs(aggregateIDs...)
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
func testSetEventTypes(eventTypes ...EventType) func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
return func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
func testSetEventTypes(eventTypes ...EventType) func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
return func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
factory = factory.EventTypes(eventTypes...)
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
func testSetResourceOwner(resourceOwner string) func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
return func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
func testSetResourceOwner(resourceOwner string) func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
return func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
factory = factory.ResourceOwner(resourceOwner)
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
func testSetSortOrder(asc bool) func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
return func(factory *SearchQueryFactory) *SearchQueryFactory {
|
||||
func testSetSortOrder(asc bool) func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
return func(factory *SearchQueryBuilder) *SearchQueryBuilder {
|
||||
if asc {
|
||||
factory = factory.OrderAsc()
|
||||
} else {
|
||||
@ -66,12 +66,12 @@ func TestSearchQueryFactorySetters(t *testing.T) {
|
||||
type args struct {
|
||||
columns Columns
|
||||
aggregateTypes []AggregateType
|
||||
setters []func(*SearchQueryFactory) *SearchQueryFactory
|
||||
setters []func(*SearchQueryBuilder) *SearchQueryBuilder
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
res *SearchQueryFactory
|
||||
res *SearchQueryBuilder
|
||||
}{
|
||||
{
|
||||
name: "New factory",
|
||||
@ -79,7 +79,7 @@ func TestSearchQueryFactorySetters(t *testing.T) {
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user", "org"},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
columns: repository.Columns(ColumnsEvent),
|
||||
aggregateTypes: []AggregateType{"user", "org"},
|
||||
},
|
||||
@ -87,54 +87,54 @@ func TestSearchQueryFactorySetters(t *testing.T) {
|
||||
{
|
||||
name: "set columns",
|
||||
args: args{
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{testSetColumns(repository.ColumnsMaxSequence)},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{testSetColumns(repository.ColumnsMaxSequence)},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
columns: repository.ColumnsMaxSequence,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set limit",
|
||||
args: args{
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{testSetLimit(100)},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{testSetLimit(100)},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
limit: 100,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set sequence",
|
||||
args: args{
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{testSetSequence(90)},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{testSetSequence(90)},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
eventSequence: 90,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set aggregateIDs",
|
||||
args: args{
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{testSetAggregateIDs("1235", "09824")},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{testSetAggregateIDs("1235", "09824")},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
aggregateIDs: []string{"1235", "09824"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set eventTypes",
|
||||
args: args{
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{testSetEventTypes("user.created", "user.updated")},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{testSetEventTypes("user.created", "user.updated")},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
eventTypes: []EventType{"user.created", "user.updated"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set resource owner",
|
||||
args: args{
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{testSetResourceOwner("hodor")},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{testSetResourceOwner("hodor")},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
resourceOwner: "hodor",
|
||||
},
|
||||
},
|
||||
@ -142,9 +142,9 @@ func TestSearchQueryFactorySetters(t *testing.T) {
|
||||
name: "default search query",
|
||||
args: args{
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{testSetAggregateIDs("1235", "024"), testSetSortOrder(false)},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{testSetAggregateIDs("1235", "024"), testSetSortOrder(false)},
|
||||
},
|
||||
res: &SearchQueryFactory{
|
||||
res: &SearchQueryBuilder{
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
aggregateIDs: []string{"1235", "024"},
|
||||
desc: true,
|
||||
@ -153,7 +153,7 @@ func TestSearchQueryFactorySetters(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
factory := NewSearchQueryFactory(tt.args.columns, tt.args.aggregateTypes...)
|
||||
factory := NewSearchQueryBuilder(tt.args.columns, tt.args.aggregateTypes...)
|
||||
for _, setter := range tt.args.setters {
|
||||
factory = setter(factory)
|
||||
}
|
||||
@ -168,7 +168,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
type args struct {
|
||||
columns Columns
|
||||
aggregateTypes []AggregateType
|
||||
setters []func(*SearchQueryFactory) *SearchQueryFactory
|
||||
setters []func(*SearchQueryBuilder) *SearchQueryBuilder
|
||||
}
|
||||
type res struct {
|
||||
isErr func(err error) bool
|
||||
@ -184,7 +184,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{},
|
||||
},
|
||||
res: res{
|
||||
isErr: errors.IsPreconditionFailed,
|
||||
@ -196,7 +196,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetColumns(Columns(-1)),
|
||||
},
|
||||
},
|
||||
@ -209,7 +209,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetColumns(math.MaxInt32),
|
||||
},
|
||||
},
|
||||
@ -222,7 +222,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{},
|
||||
},
|
||||
res: res{
|
||||
isErr: nil,
|
||||
@ -241,7 +241,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user", "org"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{},
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{},
|
||||
},
|
||||
res: res{
|
||||
isErr: nil,
|
||||
@ -260,7 +260,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetLimit(5),
|
||||
testSetSortOrder(false),
|
||||
testSetSequence(100),
|
||||
@ -284,7 +284,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetLimit(5),
|
||||
testSetSortOrder(true),
|
||||
testSetSequence(100),
|
||||
@ -308,7 +308,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetLimit(5),
|
||||
testSetSortOrder(false),
|
||||
testSetSequence(100),
|
||||
@ -333,7 +333,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetAggregateIDs("1234"),
|
||||
},
|
||||
},
|
||||
@ -355,7 +355,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetAggregateIDs("1234", "0815"),
|
||||
},
|
||||
},
|
||||
@ -377,7 +377,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetSequence(8),
|
||||
},
|
||||
},
|
||||
@ -399,7 +399,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetEventTypes("user.created"),
|
||||
},
|
||||
},
|
||||
@ -421,7 +421,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetEventTypes("user.created", "user.changed"),
|
||||
},
|
||||
},
|
||||
@ -443,7 +443,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
args: args{
|
||||
columns: ColumnsEvent,
|
||||
aggregateTypes: []AggregateType{"user"},
|
||||
setters: []func(*SearchQueryFactory) *SearchQueryFactory{
|
||||
setters: []func(*SearchQueryBuilder) *SearchQueryBuilder{
|
||||
testSetResourceOwner("hodor"),
|
||||
},
|
||||
},
|
||||
@ -473,7 +473,7 @@ func TestSearchQueryFactoryBuild(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
factory := NewSearchQueryFactory(tt.args.columns, tt.args.aggregateTypes...)
|
||||
factory := NewSearchQueryBuilder(tt.args.columns, tt.args.aggregateTypes...)
|
||||
for _, f := range tt.args.setters {
|
||||
factory = f(factory)
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ func (rm *IDPConfigReadModel) AppendEvents(events ...eventstore.EventReader) {
|
||||
}
|
||||
}
|
||||
|
||||
func (rm *IDPConfigReadModel) Query() *eventstore.SearchQueryFactory {
|
||||
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
|
||||
func (rm *IDPConfigReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).
|
||||
AggregateIDs(rm.iamID).
|
||||
EventData(map[string]interface{}{
|
||||
"idpConfigId": rm.configID,
|
||||
@ -74,8 +74,8 @@ func NewIDPConfigWriteModel(iamID, configID string) *IDPConfigWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IDPConfigWriteModel) Query() *eventstore.SearchQueryFactory {
|
||||
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
|
||||
func (wm *IDPConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).
|
||||
AggregateIDs(wm.iamID)
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,8 @@ func (wm *IDPOIDCConfigWriteModel) Reduce() error {
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IDPOIDCConfigWriteModel) Query() *eventstore.SearchQueryFactory {
|
||||
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
|
||||
func (wm *IDPOIDCConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).
|
||||
AggregateIDs(wm.iamID)
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,8 @@ func (rm *MemberReadModel) AppendEvents(events ...eventstore.EventReader) {
|
||||
}
|
||||
}
|
||||
|
||||
func (rm *MemberReadModel) Query() *eventstore.SearchQueryFactory {
|
||||
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
|
||||
func (rm *MemberReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).
|
||||
AggregateIDs(rm.iamID).
|
||||
EventData(map[string]interface{}{
|
||||
"userId": rm.userID,
|
||||
@ -94,8 +94,8 @@ func (wm *MemberWriteModel) Reduce() error {
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *MemberWriteModel) Query() *eventstore.SearchQueryFactory {
|
||||
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
|
||||
func (wm *MemberWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).
|
||||
AggregateIDs(wm.iamID)
|
||||
}
|
||||
|
||||
|
@ -109,8 +109,8 @@ func (wm *LoginPolicyIDPProviderWriteModel) Reduce() error {
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *LoginPolicyIDPProviderWriteModel) Query() *eventstore.SearchQueryFactory {
|
||||
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
|
||||
func (wm *LoginPolicyIDPProviderWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).
|
||||
AggregateIDs(wm.iamID)
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,6 @@ func (rm *ReadModel) AppendAndReduce(events ...eventstore.EventReader) error {
|
||||
return rm.Reduce()
|
||||
}
|
||||
|
||||
func (rm *ReadModel) Query() *eventstore.SearchQueryFactory {
|
||||
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).AggregateIDs(rm.AggregateID)
|
||||
func (rm *ReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, AggregateType).AggregateIDs(rm.AggregateID)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user