Add metadata to groups
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m58s
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m58s
This commit is contained in:
@@ -15,6 +15,7 @@ func (g Group) ToStorageType() storage.Group {
|
|||||||
Namespace: g.Namespace,
|
Namespace: g.Namespace,
|
||||||
Members: g.Members,
|
Members: g.Members,
|
||||||
Data: map[string]any{},
|
Data: map[string]any{},
|
||||||
|
Metadata: map[string]any{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, d := range g.Data.GetFields() {
|
for k, d := range g.Data.GetFields() {
|
||||||
@@ -28,6 +29,17 @@ func (g Group) ToStorageType() storage.Group {
|
|||||||
group.Data[k] = data
|
group.Data[k] = data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for k, d := range g.Metadata.GetFields() {
|
||||||
|
jsondata, err := protojson.Marshal(d)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
var data any
|
||||||
|
json.Unmarshal(jsondata, &data)
|
||||||
|
group.Metadata[k] = data
|
||||||
|
}
|
||||||
|
|
||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,11 +56,25 @@ func GroupFromStorageType(group *storage.Group) (*Group, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var metadata *structpb.Struct
|
||||||
|
if group.Metadata != nil {
|
||||||
|
m, err := sanitizeData(group.Metadata)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
metadata, err = structpb.NewStruct(m)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &Group{
|
return &Group{
|
||||||
Id: group.ID,
|
Id: group.ID,
|
||||||
Namespace: group.Namespace,
|
Namespace: group.Namespace,
|
||||||
Members: group.Members,
|
Members: group.Members,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
Metadata: metadata,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type Group struct {
|
|||||||
Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"`
|
Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"`
|
||||||
Members []string `protobuf:"bytes,3,rep,name=members,proto3" json:"members,omitempty"`
|
Members []string `protobuf:"bytes,3,rep,name=members,proto3" json:"members,omitempty"`
|
||||||
Data *structpb.Struct `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
|
Data *structpb.Struct `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
|
||||||
|
Metadata *structpb.Struct `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -90,16 +91,24 @@ func (x *Group) GetData() *structpb.Struct {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Group) GetMetadata() *structpb.Struct {
|
||||||
|
if x != nil {
|
||||||
|
return x.Metadata
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var File_groups_proto protoreflect.FileDescriptor
|
var File_groups_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
const file_groups_proto_rawDesc = "" +
|
const file_groups_proto_rawDesc = "" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\fgroups.proto\x1a\x1cgoogle/protobuf/struct.proto\"|\n" +
|
"\fgroups.proto\x1a\x1cgoogle/protobuf/struct.proto\"\xb1\x01\n" +
|
||||||
"\x05Group\x12\x0e\n" +
|
"\x05Group\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1c\n" +
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1c\n" +
|
||||||
"\tnamespace\x18\x02 \x01(\tR\tnamespace\x12\x18\n" +
|
"\tnamespace\x18\x02 \x01(\tR\tnamespace\x12\x18\n" +
|
||||||
"\amembers\x18\x03 \x03(\tR\amembers\x12+\n" +
|
"\amembers\x18\x03 \x03(\tR\amembers\x12+\n" +
|
||||||
"\x04data\x18\x04 \x01(\v2\x17.google.protobuf.StructR\x04dataB9Z7git.coopgo.io/coopgo-platform/groups-management/grpcapib\x06proto3"
|
"\x04data\x18\x04 \x01(\v2\x17.google.protobuf.StructR\x04data\x123\n" +
|
||||||
|
"\bmetadata\x18\x05 \x01(\v2\x17.google.protobuf.StructR\bmetadataB9Z7git.coopgo.io/coopgo-platform/groups-management/grpcapib\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_groups_proto_rawDescOnce sync.Once
|
file_groups_proto_rawDescOnce sync.Once
|
||||||
@@ -120,11 +129,12 @@ var file_groups_proto_goTypes = []any{
|
|||||||
}
|
}
|
||||||
var file_groups_proto_depIdxs = []int32{
|
var file_groups_proto_depIdxs = []int32{
|
||||||
1, // 0: Group.data:type_name -> google.protobuf.Struct
|
1, // 0: Group.data:type_name -> google.protobuf.Struct
|
||||||
1, // [1:1] is the sub-list for method output_type
|
1, // 1: Group.metadata:type_name -> google.protobuf.Struct
|
||||||
1, // [1:1] is the sub-list for method input_type
|
2, // [2:2] is the sub-list for method output_type
|
||||||
1, // [1:1] is the sub-list for extension type_name
|
2, // [2:2] is the sub-list for method input_type
|
||||||
1, // [1:1] is the sub-list for extension extendee
|
2, // [2:2] is the sub-list for extension type_name
|
||||||
0, // [0:1] is the sub-list for field type_name
|
2, // [2:2] is the sub-list for extension extendee
|
||||||
|
0, // [0:2] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_groups_proto_init() }
|
func init() { file_groups_proto_init() }
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ message Group {
|
|||||||
string namespace = 2;
|
string namespace = 2;
|
||||||
repeated string members = 3;
|
repeated string members = 3;
|
||||||
google.protobuf.Struct data = 4;
|
google.protobuf.Struct data = 4;
|
||||||
|
google.protobuf.Struct metadata = 5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ type Group struct {
|
|||||||
Namespace string `json:"namespace"`
|
Namespace string `json:"namespace"`
|
||||||
Members []string `json:"members"`
|
Members []string `json:"members"`
|
||||||
Data map[string]any `json:"data"`
|
Data map[string]any `json:"data"`
|
||||||
|
Metadata map[string]any `json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////code
|
|
||||||
type GroupMember struct {
|
type GroupMember struct {
|
||||||
ID string `json:"id" bson:"_id"`
|
ID string `json:"id" bson:"_id"`
|
||||||
Memberid string `json:"memberid"`
|
Memberid string `json:"memberid"`
|
||||||
|
|||||||
Reference in New Issue
Block a user