mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
423b86a03b
* feat: reread events * feat: sequence and timestamo on search requests * feat: sequence and timestamo on search requests * fix: better naming * fix: log errors * fix: read sequence before search request
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
"github.com/caos/logging"
|
|
auth_view "github.com/caos/zitadel/internal/auth/repository/eventsourcing/view"
|
|
org_model "github.com/caos/zitadel/internal/org/model"
|
|
org_es "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
|
"github.com/caos/zitadel/internal/org/repository/view/model"
|
|
)
|
|
|
|
type OrgRepository struct {
|
|
SearchLimit uint64
|
|
*org_es.OrgEventstore
|
|
View *auth_view.View
|
|
}
|
|
|
|
func (repo *OrgRepository) SearchOrgs(ctx context.Context, request *org_model.OrgSearchRequest) (*org_model.OrgSearchResult, error) {
|
|
request.EnsureLimit(repo.SearchLimit)
|
|
sequence, err := repo.View.GetLatestOrgSequence()
|
|
logging.Log("EVENT-7Udhz").OnError(err).Warn("could not read latest org sequence")
|
|
members, count, err := repo.View.SearchOrgs(request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := &org_model.OrgSearchResult{
|
|
Offset: request.Offset,
|
|
Limit: request.Limit,
|
|
TotalResult: uint64(count),
|
|
Result: model.OrgsToModel(members),
|
|
}
|
|
if err == nil {
|
|
result.Sequence = sequence.CurrentSequence
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
}
|
|
return result, nil
|
|
}
|