mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:07:31 +00:00
refactor(changes): use queries.SearchEvents
(#5388)
* refactor(changes): use `queries.SearchEvents` --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
@@ -9,7 +9,9 @@ import (
|
||||
object_grpc "github.com/zitadel/zitadel/internal/api/grpc/object"
|
||||
project_grpc "github.com/zitadel/zitadel/internal/api/grpc/project"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
mgmt_pb "github.com/zitadel/zitadel/pkg/grpc/management"
|
||||
)
|
||||
|
||||
@@ -39,13 +41,41 @@ func (s *Server) ListApps(ctx context.Context, req *mgmt_pb.ListAppsRequest) (*m
|
||||
}
|
||||
|
||||
func (s *Server) ListAppChanges(ctx context.Context, req *mgmt_pb.ListAppChangesRequest) (*mgmt_pb.ListAppChangesResponse, error) {
|
||||
sequence, limit, asc := change_grpc.ChangeQueryToQuery(req.Query)
|
||||
res, err := s.query.ApplicationChanges(ctx, req.ProjectId, req.AppId, sequence, limit, asc, s.auditLogRetention)
|
||||
var (
|
||||
limit uint64
|
||||
sequence uint64
|
||||
asc bool
|
||||
)
|
||||
if req.Query != nil {
|
||||
limit = uint64(req.Query.Limit)
|
||||
sequence = req.Query.Sequence
|
||||
asc = req.Query.Asc
|
||||
}
|
||||
|
||||
query := eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
AllowTimeTravel().
|
||||
Limit(limit).
|
||||
OrderDesc().
|
||||
ResourceOwner(authz.GetCtxData(ctx).OrgID).
|
||||
AddQuery().
|
||||
SequenceGreater(sequence).
|
||||
AggregateTypes(project.AggregateType).
|
||||
AggregateIDs(req.ProjectId).
|
||||
EventData(map[string]interface{}{
|
||||
"appId": req.AppId,
|
||||
}).
|
||||
Builder()
|
||||
if asc {
|
||||
query.OrderAsc()
|
||||
}
|
||||
|
||||
changes, err := s.query.SearchEvents(ctx, query, s.auditLogRetention)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &mgmt_pb.ListAppChangesResponse{
|
||||
Result: change_grpc.ChangesToPb(res.Changes, s.assetAPIPrefix(ctx)),
|
||||
Result: change_grpc.EventsToChangesPb(changes, s.assetAPIPrefix(ctx)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user