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