feat(changes): add editor (#273)

* fix(changes): add editor to change mapper

* fix(eventstore): only add latest sequence if greater 0 to query

* sort order in request for changes

* fix(changes): map editor for org, app and project
This commit is contained in:
Silvan
2020-06-25 11:25:38 +02:00
committed by GitHub
parent 62b654ea18
commit d947bb1247
27 changed files with 13484 additions and 14053 deletions

View File

@@ -3,9 +3,10 @@ package eventsourcing
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/config/systemdefaults"
"log"
"github.com/caos/zitadel/internal/config/systemdefaults"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
@@ -194,8 +195,8 @@ func (es *OrgEventstore) RemoveOrgDomain(ctx context.Context, domain *org_model.
return nil
}
func (es *OrgEventstore) OrgChanges(ctx context.Context, id string, lastSequence uint64, limit uint64) (*org_model.OrgChanges, error) {
query := ChangesQuery(id, lastSequence)
func (es *OrgEventstore) OrgChanges(ctx context.Context, id string, lastSequence uint64, limit uint64, sortAscending bool) (*org_model.OrgChanges, error) {
query := ChangesQuery(id, lastSequence, limit, sortAscending)
events, err := es.Eventstore.FilterEvents(context.Background(), query)
if err != nil {
@@ -240,11 +241,17 @@ func (es *OrgEventstore) OrgChanges(ctx context.Context, id string, lastSequence
return changes, nil
}
func ChangesQuery(orgID string, latestSequence uint64) *es_models.SearchQuery {
func ChangesQuery(orgID string, latestSequence, limit uint64, sortAscending bool) *es_models.SearchQuery {
query := es_models.NewSearchQuery().
AggregateTypeFilter(model.OrgAggregate).
LatestSequenceFilter(latestSequence).
AggregateIDFilter(orgID)
AggregateTypeFilter(model.OrgAggregate)
if !sortAscending {
query.OrderDesc() //TODO: configure from param
}
query.LatestSequenceFilter(latestSequence).
AggregateIDFilter(orgID).
SetLimit(limit)
return query
}

View File

@@ -1077,7 +1077,7 @@ func TestChangesOrg(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := tt.args.es.OrgChanges(nil, tt.args.id, tt.args.lastSequence, tt.args.limit)
result, err := tt.args.es.OrgChanges(nil, tt.args.id, tt.args.lastSequence, tt.args.limit, false)
org := &model.Org{}
if result != nil && len(result.Changes) > 0 {