From 51e10e9e3cc594d3ba91c10527a1a4edd3d42039 Mon Sep 17 00:00:00 2001 From: Jony Bepary Date: Sat, 21 Oct 2023 17:38:41 +0600 Subject: [PATCH] Add comments struct & message to the model --- internal/model/comments.pb.go | 173 +++++++++++++++++++++++----------- internal/model/comments.proto | 9 +- 2 files changed, 126 insertions(+), 56 deletions(-) diff --git a/internal/model/comments.pb.go b/internal/model/comments.pb.go index 65fecbe..4710796 100644 --- a/internal/model/comments.pb.go +++ b/internal/model/comments.pb.go @@ -31,7 +31,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type Comments struct { +type Comment struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -44,13 +44,13 @@ type Comments struct { CreatedDate *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=created_date,json=createdDate,proto3" json:"created_date,omitempty"` UpdatedDate *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=updated_date,json=updatedDate,proto3" json:"updated_date,omitempty"` Likes int64 `protobuf:"varint,8,opt,name=likes,proto3" json:"likes,omitempty"` - Replies int64 `protobuf:"varint,9,opt,name=replies,proto3" json:"replies,omitempty"` + Replies []string `protobuf:"bytes,9,rep,name=replies,proto3" json:"replies,omitempty"` IsDeleted bool `protobuf:"varint,10,opt,name=is_deleted,json=isDeleted,proto3" json:"is_deleted,omitempty"` IsUpdated bool `protobuf:"varint,11,opt,name=is_updated,json=isUpdated,proto3" json:"is_updated,omitempty"` } -func (x *Comments) Reset() { - *x = Comments{} +func (x *Comment) Reset() { + *x = Comment{} if protoimpl.UnsafeEnabled { mi := &file_comments_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -58,13 +58,13 @@ func (x *Comments) Reset() { } } -func (x *Comments) String() string { +func (x *Comment) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Comments) ProtoMessage() {} +func (*Comment) ProtoMessage() {} -func (x *Comments) ProtoReflect() protoreflect.Message { +func (x *Comment) ProtoReflect() protoreflect.Message { mi := &file_comments_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -76,118 +76,169 @@ func (x *Comments) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Comments.ProtoReflect.Descriptor instead. -func (*Comments) Descriptor() ([]byte, []int) { +// Deprecated: Use Comment.ProtoReflect.Descriptor instead. +func (*Comment) Descriptor() ([]byte, []int) { return file_comments_proto_rawDescGZIP(), []int{0} } -func (x *Comments) GetId() string { +func (x *Comment) GetId() string { if x != nil { return x.Id } return "" } -func (x *Comments) GetUser() string { +func (x *Comment) GetUser() string { if x != nil { return x.User } return "" } -func (x *Comments) GetPostId() string { +func (x *Comment) GetPostId() string { if x != nil { return x.PostId } return "" } -func (x *Comments) GetUserId() string { +func (x *Comment) GetUserId() string { if x != nil { return x.UserId } return "" } -func (x *Comments) GetText() string { +func (x *Comment) GetText() string { if x != nil { return x.Text } return "" } -func (x *Comments) GetCreatedDate() *timestamppb.Timestamp { +func (x *Comment) GetCreatedDate() *timestamppb.Timestamp { if x != nil { return x.CreatedDate } return nil } -func (x *Comments) GetUpdatedDate() *timestamppb.Timestamp { +func (x *Comment) GetUpdatedDate() *timestamppb.Timestamp { if x != nil { return x.UpdatedDate } return nil } -func (x *Comments) GetLikes() int64 { +func (x *Comment) GetLikes() int64 { if x != nil { return x.Likes } return 0 } -func (x *Comments) GetReplies() int64 { +func (x *Comment) GetReplies() []string { if x != nil { return x.Replies } - return 0 + return nil } -func (x *Comments) GetIsDeleted() bool { +func (x *Comment) GetIsDeleted() bool { if x != nil { return x.IsDeleted } return false } -func (x *Comments) GetIsUpdated() bool { +func (x *Comment) GetIsUpdated() bool { if x != nil { return x.IsUpdated } return false } +type Comments struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Comments []*Comment `protobuf:"bytes,1,rep,name=comments,proto3" json:"comments,omitempty"` +} + +func (x *Comments) Reset() { + *x = Comments{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Comments) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Comments) ProtoMessage() {} + +func (x *Comments) ProtoReflect() protoreflect.Message { + mi := &file_comments_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Comments.ProtoReflect.Descriptor instead. +func (*Comments) Descriptor() ([]byte, []int) { + return file_comments_proto_rawDescGZIP(), []int{1} +} + +func (x *Comments) GetComments() []*Comment { + if x != nil { + return x.Comments + } + return nil +} + var File_comments_proto protoreflect.FileDescriptor var file_comments_proto_rawDesc = []byte{ 0x0a, 0x0e, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe0, 0x02, 0x0a, 0x08, 0x43, 0x6f, 0x6d, - 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x6f, 0x73, - 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x6f, 0x73, 0x74, - 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, - 0x65, 0x78, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, - 0x3d, 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, - 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, - 0x70, 0x52, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x65, 0x12, 0x3d, - 0x0a, 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x07, + 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdf, 0x02, 0x0a, 0x07, 0x43, 0x6f, 0x6d, + 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x6f, 0x73, 0x74, + 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x6f, 0x73, 0x74, 0x49, + 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, + 0x78, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x3d, + 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x65, 0x12, 0x14, 0x0a, - 0x05, 0x6c, 0x69, 0x6b, 0x65, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6c, 0x69, - 0x6b, 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x12, 0x1d, 0x0a, - 0x0a, 0x69, 0x73, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x09, 0x69, 0x73, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x12, 0x1d, 0x0a, 0x0a, - 0x69, 0x73, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x09, 0x69, 0x73, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x42, 0x09, 0x5a, 0x07, 0x2e, - 0x3b, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x65, 0x12, 0x3d, 0x0a, + 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x65, 0x12, 0x14, 0x0a, 0x05, + 0x6c, 0x69, 0x6b, 0x65, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6c, 0x69, 0x6b, + 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x18, 0x09, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, + 0x69, 0x73, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x09, 0x69, 0x73, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x69, + 0x73, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x09, 0x69, 0x73, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x22, 0x36, 0x0a, 0x08, 0x43, 0x6f, + 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x2a, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, + 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, + 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, + 0x74, 0x73, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -202,19 +253,21 @@ func file_comments_proto_rawDescGZIP() []byte { return file_comments_proto_rawDescData } -var file_comments_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_comments_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_comments_proto_goTypes = []interface{}{ - (*Comments)(nil), // 0: model.Comments - (*timestamppb.Timestamp)(nil), // 1: google.protobuf.Timestamp + (*Comment)(nil), // 0: model.Comment + (*Comments)(nil), // 1: model.Comments + (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp } var file_comments_proto_depIdxs = []int32{ - 1, // 0: model.Comments.created_date:type_name -> google.protobuf.Timestamp - 1, // 1: model.Comments.updated_date:type_name -> google.protobuf.Timestamp - 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 + 2, // 0: model.Comment.created_date:type_name -> google.protobuf.Timestamp + 2, // 1: model.Comment.updated_date:type_name -> google.protobuf.Timestamp + 0, // 2: model.Comments.comments:type_name -> model.Comment + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_comments_proto_init() } @@ -224,6 +277,18 @@ func file_comments_proto_init() { } if !protoimpl.UnsafeEnabled { file_comments_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Comment); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Comments); i { case 0: return &v.state @@ -242,7 +307,7 @@ func file_comments_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_comments_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/internal/model/comments.proto b/internal/model/comments.proto index 05dc504..1bc23ec 100644 --- a/internal/model/comments.proto +++ b/internal/model/comments.proto @@ -14,7 +14,7 @@ package model; option go_package = ".;model"; import "google/protobuf/timestamp.proto"; -message Comments{ +message Comment{ string id = 1; string user = 2; string post_id = 3; @@ -23,8 +23,13 @@ message Comments{ google.protobuf.Timestamp created_date = 6 ; google.protobuf.Timestamp updated_date = 7 ; int64 likes = 8; - int64 replies = 9; + repeated string replies = 9; bool is_deleted = 10; bool is_updated = 11; } + +message Comments { + repeated Comment comments = 1; +} +