Add metadata to groups
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m58s

This commit is contained in:
Arnaud Delcasse
2026-01-13 22:08:54 +01:00
parent eb884ab52d
commit 68912e17a0
4 changed files with 46 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ func (g Group) ToStorageType() storage.Group {
Namespace: g.Namespace,
Members: g.Members,
Data: map[string]any{},
Metadata: map[string]any{},
}
for k, d := range g.Data.GetFields() {
@@ -28,6 +29,17 @@ func (g Group) ToStorageType() storage.Group {
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
}
@@ -44,11 +56,25 @@ func GroupFromStorageType(group *storage.Group) (*Group, error) {
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{
Id: group.ID,
Namespace: group.Namespace,
Members: group.Members,
Data: data,
Metadata: metadata,
}, nil
}

View File

@@ -28,6 +28,7 @@ type Group struct {
Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,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"`
Metadata *structpb.Struct `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -90,16 +91,24 @@ func (x *Group) GetData() *structpb.Struct {
return nil
}
func (x *Group) GetMetadata() *structpb.Struct {
if x != nil {
return x.Metadata
}
return nil
}
var File_groups_proto protoreflect.FileDescriptor
const file_groups_proto_rawDesc = "" +
"\n" +
"\fgroups.proto\x1a\x1cgoogle/protobuf/struct.proto\"|\n" +
"\fgroups.proto\x1a\x1cgoogle/protobuf/struct.proto\"\xb1\x01\n" +
"\x05Group\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1c\n" +
"\tnamespace\x18\x02 \x01(\tR\tnamespace\x12\x18\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 (
file_groups_proto_rawDescOnce sync.Once
@@ -120,11 +129,12 @@ var file_groups_proto_goTypes = []any{
}
var file_groups_proto_depIdxs = []int32{
1, // 0: Group.data:type_name -> google.protobuf.Struct
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
1, // 1: Group.metadata:type_name -> google.protobuf.Struct
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension 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() }

View File

@@ -6,7 +6,8 @@ import "google/protobuf/struct.proto";
message Group {
string id = 1;
string namespace = 2;
string namespace = 2;
repeated string members = 3;
google.protobuf.Struct data = 4;
google.protobuf.Struct metadata = 5;
}

View File

@@ -5,9 +5,9 @@ type Group struct {
Namespace string `json:"namespace"`
Members []string `json:"members"`
Data map[string]any `json:"data"`
Metadata map[string]any `json:"metadata"`
}
///////////////////code
type GroupMember struct {
ID string `json:"id" bson:"_id"`
Memberid string `json:"memberid"`