mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package iam
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
"github.com/caos/zitadel/internal/tracing"
|
|
iam_repo "github.com/caos/zitadel/internal/v2/repository/iam"
|
|
)
|
|
|
|
type Repository struct {
|
|
eventstore *eventstore.Eventstore
|
|
}
|
|
|
|
type Config struct {
|
|
Eventstore *eventstore.Eventstore
|
|
}
|
|
|
|
func StartRepository(config *Config) *Repository {
|
|
return &Repository{
|
|
eventstore: config.Eventstore,
|
|
}
|
|
}
|
|
|
|
func (r *Repository) IAMByID(ctx context.Context, id string) (_ *iam_model.IAM, err error) {
|
|
readModel, err := r.iamByID(ctx, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return readModelToIAM(readModel), nil
|
|
}
|
|
|
|
func (r *Repository) iamByID(ctx context.Context, id string) (_ *iam_repo.ReadModel, err error) {
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
query := eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, iam_repo.AggregateType).AggregateIDs(id)
|
|
|
|
readModel := new(iam_repo.ReadModel)
|
|
err = r.eventstore.FilterToReducer(ctx, query, readModel)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return readModel, nil
|
|
}
|