package document import ( "context" "forge.cadoles.com/arcad/edge/pkg/storage" "forge.cadoles.com/arcad/edge/pkg/storage/filter" "github.com/pkg/errors" ) type QueryDocumentsArgs struct { Collection string Filter map[string]any Options *storage.QueryOptions } type QueryDocumentsReply struct { Documents []storage.Document } func (s *Service) QueryDocuments(ctx context.Context, args QueryDocumentsArgs, reply *QueryDocumentsReply) error { var ( argsFilter *filter.Filter err error ) if args.Filter != nil { argsFilter, err = filter.NewFrom(args.Filter) if err != nil { return errors.WithStack(err) } } documents, err := s.store.Query(ctx, args.Collection, argsFilter, withQueryOptions(args.Options)) if err != nil { return errors.WithStack(err) } *reply = QueryDocumentsReply{ Documents: documents, } return nil } func withQueryOptions(opts *storage.QueryOptions) storage.QueryOptionFunc { return func(o *storage.QueryOptions) { o.Limit = opts.Limit o.Offset = opts.Offset o.OrderBy = opts.OrderBy o.OrderDirection = opts.OrderDirection } }