mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
c07ed83c41
* feat: eventstore repository * fix: remove gorm * version * feat: pkg * feat: add some files for project * feat: eventstore without eventstore-lib * rename files * gnueg * fix: key json * fix: add object * fix: change imports * fix: internal models * fix: some imports * fix: global model * fix: add some functions on repo * feat(eventstore): sdk * fix(eventstore): search query * fix(eventstore): rename app to eventstore * delete empty test * remove unused func * merge master * fix(eventstore): tests * fix(models): delete unused struct * fix: some funcitons * feat(eventstore): implemented push events * fix: move project eventstore to project package * fix: change project eventstore funcs * feat(eventstore): overwrite context data * fix: change project eventstore * fix: add project repo to mgmt server * feat(types): SQL-config * fix: commented code * feat(eventstore): options to overwrite editor * feat: auth interceptor and cockroach migrations * fix: migrations * fix: fix filter * fix: not found on getbyid * fix: add sequence * fix: add some tests * fix(eventstore): nullable sequence * fix: add some tests * merge * fix: add some tests * fix(migrations): correct statements for sequence * fix: add some tests * fix: add some tests * fix: changes from mr * Update internal/eventstore/models/field.go Co-Authored-By: livio-a <livio.a@gmail.com> * fix(eventstore): code quality * fix: add types to aggregate/Event-types * fix(eventstore): rename modifier* to editor* * fix(eventstore): delete editor_org * fix(migrations): remove editor_org field, rename modifier_* to editor_* * fix: generate files * fix(eventstore): tests * fix(eventstore): rename modifier to editor * fix(migrations): add cluster migration, fix(migrations): fix typo of host in clean clsuter * fix(eventstore): move health * fix(eventstore): AggregateTypeFilter aggregateType as param * code quality * feat: start implementing project members * feat: remove member funcs * feat: remove member model * feat: remove member events * feat: remove member repo model * fix: better error func testing * Update docs/local.md Co-Authored-By: Silvan <silvan.reusser@gmail.com> * Update docs/local.md Co-Authored-By: Silvan <silvan.reusser@gmail.com> * fix: mr requests * fix: md file Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: livio-a <livio.a@gmail.com>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/internal/repository"
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
)
|
|
|
|
type Eventstore interface {
|
|
AggregateCreator() *models.AggregateCreator
|
|
Health(ctx context.Context) error
|
|
PushAggregates(ctx context.Context, aggregates ...*models.Aggregate) error
|
|
FilterEvents(ctx context.Context, searchQuery *models.SearchQuery) (events []*models.Event, err error)
|
|
}
|
|
|
|
var _ Eventstore = (*eventstore)(nil)
|
|
|
|
type eventstore struct {
|
|
repo repository.Repository
|
|
aggregateCreator *models.AggregateCreator
|
|
}
|
|
|
|
func (es *eventstore) AggregateCreator() *models.AggregateCreator {
|
|
return es.aggregateCreator
|
|
}
|
|
|
|
func (es *eventstore) PushAggregates(ctx context.Context, aggregates ...*models.Aggregate) (err error) {
|
|
for _, aggregate := range aggregates {
|
|
if len(aggregate.Events) == 0 {
|
|
return errors.ThrowInvalidArgument(nil, "EVENT-cNhIj", "no events in aggregate")
|
|
}
|
|
for _, event := range aggregate.Events {
|
|
if err = event.Validate(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
err = es.repo.PushAggregates(ctx, aggregates...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, aggregate := range aggregates {
|
|
if aggregate.Appender != nil {
|
|
aggregate.Appender(aggregate.Events...)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (es *eventstore) FilterEvents(ctx context.Context, searchQuery *models.SearchQuery) ([]*models.Event, error) {
|
|
if err := searchQuery.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
return es.repo.Filter(ctx, searchQuery)
|
|
}
|
|
|
|
func (es *eventstore) Health(ctx context.Context) error {
|
|
return es.repo.Health(ctx)
|
|
}
|