2020-05-18 11:32:16 +02:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-10-20 19:10:23 +02:00
|
|
|
|
2020-05-18 11:32:16 +02:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2021-02-23 15:13:04 +01:00
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
2020-05-18 11:32:16 +02:00
|
|
|
"github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
|
|
)
|
|
|
|
|
2020-08-26 09:56:23 +02:00
|
|
|
func IAMByIDQuery(id string, latestSequence uint64) (*es_models.SearchQuery, error) {
|
2020-05-18 11:32:16 +02:00
|
|
|
if id == "" {
|
2020-08-26 09:56:23 +02:00
|
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-0soe4", "Errors.IAM.IDMissing")
|
2020-05-18 11:32:16 +02:00
|
|
|
}
|
2020-08-26 09:56:23 +02:00
|
|
|
return IAMQuery(latestSequence).
|
2020-05-18 11:32:16 +02:00
|
|
|
AggregateIDFilter(id), nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 09:56:23 +02:00
|
|
|
func IAMQuery(latestSequence uint64) *es_models.SearchQuery {
|
2020-05-18 11:32:16 +02:00
|
|
|
return es_models.NewSearchQuery().
|
2020-08-26 09:56:23 +02:00
|
|
|
AggregateTypeFilter(model.IAMAggregate).
|
2020-05-18 11:32:16 +02:00
|
|
|
LatestSequenceFilter(latestSequence)
|
|
|
|
}
|
|
|
|
|
2020-08-26 09:56:23 +02:00
|
|
|
func IAMAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, iam *model.IAM) (*es_models.Aggregate, error) {
|
2020-05-18 11:32:16 +02:00
|
|
|
if iam == nil {
|
2020-06-22 13:51:44 +02:00
|
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-lo04e", "Errors.Internal")
|
2020-05-18 11:32:16 +02:00
|
|
|
}
|
2020-08-26 09:56:23 +02:00
|
|
|
return aggCreator.NewAggregate(ctx, iam.AggregateID, model.IAMAggregate, model.IAMVersion, iam.Sequence)
|
2020-05-18 11:32:16 +02:00
|
|
|
}
|