2021-02-23 14:13:04 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-02-27 21:36:43 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/internal/repository"
|
|
|
|
z_sql "github.com/zitadel/zitadel/internal/eventstore/v1/internal/repository/sql"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2023-08-18 07:21:31 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
2021-02-23 14:13:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Eventstore interface {
|
|
|
|
Health(ctx context.Context) error
|
|
|
|
FilterEvents(ctx context.Context, searchQuery *models.SearchQuery) (events []*models.Event, err error)
|
|
|
|
Subscribe(aggregates ...models.AggregateType) *Subscription
|
2022-07-22 10:08:39 +00:00
|
|
|
InstanceIDs(ctx context.Context, searchQuery *models.SearchQuery) ([]string, error)
|
2021-02-23 14:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ Eventstore = (*eventstore)(nil)
|
|
|
|
|
|
|
|
type eventstore struct {
|
2021-02-24 10:17:39 +00:00
|
|
|
repo repository.Repository
|
2021-02-23 14:13:04 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 14:56:51 +00:00
|
|
|
func Start(db *database.DB, allowOrderByCreationDate bool) (Eventstore, error) {
|
2022-02-14 16:22:30 +00:00
|
|
|
return &eventstore{
|
2023-04-28 14:56:51 +00:00
|
|
|
repo: z_sql.Start(db, allowOrderByCreationDate),
|
2022-02-14 16:22:30 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-08-18 07:21:31 +00:00
|
|
|
func (es *eventstore) FilterEvents(ctx context.Context, searchQuery *models.SearchQuery) (_ []*models.Event, err error) {
|
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
if err := searchQuery.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return es.repo.Filter(ctx, models.FactoryFromSearchQuery(searchQuery))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (es *eventstore) Health(ctx context.Context) error {
|
|
|
|
return es.repo.Health(ctx)
|
|
|
|
}
|
2022-07-22 10:08:39 +00:00
|
|
|
|
|
|
|
func (es *eventstore) InstanceIDs(ctx context.Context, searchQuery *models.SearchQuery) ([]string, error) {
|
|
|
|
if err := searchQuery.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return es.repo.InstanceIDs(ctx, models.FactoryFromSearchQuery(searchQuery))
|
|
|
|
}
|