Skip to content
Snippets Groups Projects
Commit 178ac237 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-2202-MetaDataFromRequest' into 'master'

Добавлена функция получения метаданных из запроса к actions

See merge request perxis/perxis-go!208
parents 2896c032 18f98d06
No related branches found
No related tags found
No related merge requests found
package extension package extension
import ( import (
"strings"
"git.perx.ru/perxis/perxis-go/pkg/references" "git.perx.ru/perxis/perxis-go/pkg/references"
pb "git.perx.ru/perxis/perxis-go/proto/extensions" pb "git.perx.ru/perxis/perxis-go/proto/extensions"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
...@@ -274,3 +276,28 @@ func ActionToPB(a *Action) *pb.Action { ...@@ -274,3 +276,28 @@ func ActionToPB(a *Action) *pb.Action {
Order: a.Order, Order: a.Order,
} }
} }
func (r *ActionRequest) NewSubRequest() *ActionRequest {
md := map[string]string{
"request_extension": r.Extension,
"request_action": r.Action,
"request_space_id": r.SpaceID,
"request_env_id": r.EnvID,
"request_collection_id": r.CollectionID,
"request_item_id": r.ItemID,
"request_item_ids": strings.Join(r.ItemIDs, ","),
"request_fields": strings.Join(r.Fields, ","),
"request_refs": references.ReferenceListToString(r.Refs),
"request_params": r.Params.String(),
}
for k, v := range r.Metadata {
if _, exist := md[k]; !exist {
md[k] = v
}
}
return &ActionRequest{
Metadata: md,
}
}
package references package references
import ( import (
"strings"
"git.perx.ru/perxis/perxis-go/pkg/items" "git.perx.ru/perxis/perxis-go/pkg/items"
pb "git.perx.ru/perxis/perxis-go/proto/references" pb "git.perx.ru/perxis/perxis-go/proto/references"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
...@@ -82,6 +84,22 @@ func ReferenceListToPB(refs []*Reference) []*pb.Reference { ...@@ -82,6 +84,22 @@ func ReferenceListToPB(refs []*Reference) []*pb.Reference {
return list return list
} }
func ReferenceListToString(refs []*Reference) string {
var res strings.Builder
for _, ref := range refs {
res.WriteString(ref.String())
}
return res.String()
}
func ReferenceListToStrings(refs []*Reference) (res []string) {
for _, ref := range refs {
res = append(res, ref.String())
}
return
}
func (r *Reference) String() string { func (r *Reference) String() string {
if r == nil { if r == nil {
return "" return ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment