From 68912e17a04eb14cd01e1c6282da18cc434411a9 Mon Sep 17 00:00:00 2001 From: Arnaud Delcasse Date: Tue, 13 Jan 2026 22:08:54 +0100 Subject: [PATCH] Add metadata to groups --- grpcapi/groups.go | 26 ++++++++++++++++++++++++++ grpcapi/groups.pb.go | 24 +++++++++++++++++------- grpcapi/groups.proto | 3 ++- storage/groups.go | 2 +- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/grpcapi/groups.go b/grpcapi/groups.go index 18c7e49..f42e5c1 100644 --- a/grpcapi/groups.go +++ b/grpcapi/groups.go @@ -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 } diff --git a/grpcapi/groups.pb.go b/grpcapi/groups.pb.go index 973d093..44070d4 100644 --- a/grpcapi/groups.pb.go +++ b/grpcapi/groups.pb.go @@ -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() } diff --git a/grpcapi/groups.proto b/grpcapi/groups.proto index 65e8c6b..33a96d3 100644 --- a/grpcapi/groups.proto +++ b/grpcapi/groups.proto @@ -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; } diff --git a/storage/groups.go b/storage/groups.go index 2096e84..a472241 100644 --- a/storage/groups.go +++ b/storage/groups.go @@ -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"`