diff --git a/cmd/media_service/main.go b/cmd/media_service/main.go new file mode 100644 index 0000000..f52dcde --- /dev/null +++ b/cmd/media_service/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "github.com/joho/godotenv" + "monify/lib/utils" + "monify/services/media" +) + +func main() { + //Load secrets + _ = godotenv.Load() + secrets, err := utils.LoadSecrets(utils.LoadEnv()) + if err != nil { + panic(err) + } + infra, err := media.Setup(media.NewConfig(secrets)) + if err != nil { + panic(err) + } + media.NewServer(infra).Start() +} diff --git a/protobuf/gen/go/group.pb.go b/protobuf/gen/go/group.pb.go index cff6c69..2bc5760 100644 --- a/protobuf/gen/go/group.pb.go +++ b/protobuf/gen/go/group.pb.go @@ -893,6 +893,171 @@ func (x *GetInviteCodeResponse) GetExpiresAfter() *durationpb.Duration { return nil } +type GetGroupInfoRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"` +} + +func (x *GetGroupInfoRequest) Reset() { + *x = GetGroupInfoRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_group_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetGroupInfoRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetGroupInfoRequest) ProtoMessage() {} + +func (x *GetGroupInfoRequest) ProtoReflect() protoreflect.Message { + mi := &file_group_proto_msgTypes[17] + 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 GetGroupInfoRequest.ProtoReflect.Descriptor instead. +func (*GetGroupInfoRequest) Descriptor() ([]byte, []int) { + return file_group_proto_rawDescGZIP(), []int{17} +} + +func (x *GetGroupInfoRequest) GetGroupId() string { + if x != nil { + return x.GroupId + } + return "" +} + +type GetGroupInfoResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + GroupId string `protobuf:"bytes,1,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` + AvatarUrl string `protobuf:"bytes,4,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"` +} + +func (x *GetGroupInfoResponse) Reset() { + *x = GetGroupInfoResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_group_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetGroupInfoResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetGroupInfoResponse) ProtoMessage() {} + +func (x *GetGroupInfoResponse) ProtoReflect() protoreflect.Message { + mi := &file_group_proto_msgTypes[18] + 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 GetGroupInfoResponse.ProtoReflect.Descriptor instead. +func (*GetGroupInfoResponse) Descriptor() ([]byte, []int) { + return file_group_proto_rawDescGZIP(), []int{18} +} + +func (x *GetGroupInfoResponse) GetGroupId() string { + if x != nil { + return x.GroupId + } + return "" +} + +func (x *GetGroupInfoResponse) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *GetGroupInfoResponse) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *GetGroupInfoResponse) GetAvatarUrl() string { + if x != nil { + return x.AvatarUrl + } + return "" +} + +type GetGroupByInviteCodeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + InviteCode string `protobuf:"bytes,1,opt,name=invite_code,json=inviteCode,proto3" json:"invite_code,omitempty"` +} + +func (x *GetGroupByInviteCodeRequest) Reset() { + *x = GetGroupByInviteCodeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_group_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetGroupByInviteCodeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetGroupByInviteCodeRequest) ProtoMessage() {} + +func (x *GetGroupByInviteCodeRequest) ProtoReflect() protoreflect.Message { + mi := &file_group_proto_msgTypes[19] + 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 GetGroupByInviteCodeRequest.ProtoReflect.Descriptor instead. +func (*GetGroupByInviteCodeRequest) Descriptor() ([]byte, []int) { + return file_group_proto_rawDescGZIP(), []int{19} +} + +func (x *GetGroupByInviteCodeRequest) GetInviteCode() string { + if x != nil { + return x.InviteCode + } + return "" +} + var File_group_proto protoreflect.FileDescriptor var file_group_proto_rawDesc = []byte{ @@ -975,58 +1140,87 @@ var file_group_proto_rawDesc = []byte{ 0x73, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, - 0x73, 0x41, 0x66, 0x74, 0x65, 0x72, 0x32, 0x80, 0x06, 0x0a, 0x0c, 0x47, 0x72, 0x6f, 0x75, 0x70, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5f, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x13, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x47, - 0x72, 0x6f, 0x75, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x25, 0x92, 0x41, 0x0e, 0x62, 0x0c, 0x0a, 0x0a, 0x0a, 0x06, 0x42, 0x65, 0x61, 0x72, - 0x65, 0x72, 0x12, 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x3a, 0x01, 0x2a, 0x22, 0x09, 0x2f, - 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x4f, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, - 0x4a, 0x6f, 0x69, 0x6e, 0x65, 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x73, 0x12, 0x06, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x19, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4a, 0x6f, 0x69, 0x6e, 0x65, - 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, - 0x75, 0x70, 0x2f, 0x6a, 0x6f, 0x69, 0x6e, 0x65, 0x64, 0x12, 0x6f, 0x0a, 0x12, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x12, - 0x1a, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, - 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x47, 0x65, - 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x20, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1a, - 0x3a, 0x01, 0x2a, 0x22, 0x15, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x69, - 0x6e, 0x76, 0x69, 0x74, 0x65, 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x4d, 0x0a, 0x09, 0x4a, 0x6f, - 0x69, 0x6e, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x11, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x47, 0x72, - 0x6f, 0x75, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x4a, 0x6f, 0x69, - 0x6e, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x3a, 0x01, 0x2a, 0x22, 0x0e, 0x2f, 0x76, 0x31, 0x2f, 0x67, - 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x6a, 0x6f, 0x69, 0x6e, 0x12, 0x6a, 0x0a, 0x0f, 0x47, 0x65, 0x74, - 0x47, 0x72, 0x6f, 0x75, 0x70, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x12, 0x17, 0x2e, 0x47, - 0x65, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, - 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x24, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x12, 0x1c, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, - 0x75, 0x70, 0x2f, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x2f, 0x7b, 0x67, 0x72, 0x6f, 0x75, - 0x70, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x48, 0x0a, 0x0b, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x47, - 0x72, 0x6f, 0x75, 0x70, 0x12, 0x13, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x47, 0x72, 0x6f, - 0x75, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x2a, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x67, - 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x7b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x7d, 0x12, - 0x5e, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, - 0x6f, 0x64, 0x65, 0x12, 0x18, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, - 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x2a, 0x20, 0x2f, - 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x2d, - 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x7b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x7d, 0x12, - 0x68, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, - 0x12, 0x15, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x76, - 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x12, 0x20, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, - 0x75, 0x70, 0x2f, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x7b, - 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x7d, 0x42, 0x1e, 0x5a, 0x1c, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x53, 0x70, 0x65, 0x65, 0x64, 0x52, 0x65, 0x61, - 0x63, 0x68, 0x2f, 0x6d, 0x6f, 0x6e, 0x69, 0x66, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x73, 0x41, 0x66, 0x74, 0x65, 0x72, 0x22, 0x30, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, + 0x75, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, + 0x08, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x22, 0x86, 0x01, 0x0a, 0x14, 0x47, 0x65, 0x74, + 0x47, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x5f, 0x75, 0x72, 0x6c, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, 0x72, + 0x6c, 0x22, 0x3e, 0x0a, 0x1b, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x42, 0x79, 0x49, + 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, + 0x65, 0x32, 0xdd, 0x07, 0x0a, 0x0c, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0x5f, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x47, 0x72, 0x6f, 0x75, + 0x70, 0x12, 0x13, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x47, + 0x72, 0x6f, 0x75, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, 0x92, 0x41, + 0x0e, 0x62, 0x0c, 0x0a, 0x0a, 0x0a, 0x06, 0x42, 0x65, 0x61, 0x72, 0x65, 0x72, 0x12, 0x00, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x3a, 0x01, 0x2a, 0x22, 0x09, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, + 0x6f, 0x75, 0x70, 0x12, 0x4f, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x4a, 0x6f, 0x69, 0x6e, 0x65, + 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x73, 0x12, 0x06, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, + 0x19, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4a, 0x6f, 0x69, 0x6e, 0x65, 0x64, 0x47, 0x72, 0x6f, 0x75, + 0x70, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x6a, 0x6f, + 0x69, 0x6e, 0x65, 0x64, 0x12, 0x6f, 0x0a, 0x12, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, + 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1a, 0x2e, 0x47, 0x65, 0x6e, + 0x65, 0x72, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, + 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x20, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x3a, 0x01, 0x2a, 0x22, 0x15, + 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, + 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x4d, 0x0a, 0x09, 0x4a, 0x6f, 0x69, 0x6e, 0x47, 0x72, 0x6f, + 0x75, 0x70, 0x12, 0x11, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x47, 0x72, 0x6f, 0x75, + 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x13, 0x3a, 0x01, 0x2a, 0x22, 0x0e, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, + 0x6a, 0x6f, 0x69, 0x6e, 0x12, 0x6a, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, + 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x12, 0x17, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, + 0x75, 0x70, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x18, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x4d, 0x65, 0x6d, 0x62, 0x65, + 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x24, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x1e, 0x12, 0x1c, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x6d, 0x65, + 0x6d, 0x62, 0x65, 0x72, 0x73, 0x2f, 0x7b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x7d, + 0x12, 0x48, 0x0a, 0x0b, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x12, + 0x13, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x1c, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x16, 0x2a, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, + 0x7b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x5e, 0x0a, 0x10, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, + 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x2a, 0x20, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, + 0x6f, 0x75, 0x70, 0x2f, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x2f, + 0x7b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x6c, 0x0a, 0x0d, 0x47, 0x65, + 0x74, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x15, 0x2e, 0x47, 0x65, + 0x74, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, + 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x26, 0x12, 0x24, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x69, 0x6e, + 0x76, 0x69, 0x74, 0x65, 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x67, 0x32, 0x69, 0x2f, 0x7b, 0x67, + 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x59, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x47, + 0x72, 0x6f, 0x75, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x72, + 0x6f, 0x75, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, + 0x2e, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x12, 0x14, 0x2f, + 0x76, 0x31, 0x2f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x7b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, + 0x69, 0x64, 0x7d, 0x12, 0x7c, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x42, + 0x79, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1c, 0x2e, 0x47, 0x65, + 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x42, 0x79, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, + 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x47, 0x65, 0x74, 0x47, + 0x72, 0x6f, 0x75, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x2f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x29, 0x12, 0x27, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, + 0x6f, 0x75, 0x70, 0x2f, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x2f, + 0x69, 0x32, 0x67, 0x2f, 0x7b, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x5f, 0x63, 0x6f, 0x64, 0x65, + 0x7d, 0x42, 0x1e, 0x5a, 0x1c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x53, 0x70, 0x65, 0x65, 0x64, 0x52, 0x65, 0x61, 0x63, 0x68, 0x2f, 0x6d, 0x6f, 0x6e, 0x69, 0x66, + 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1041,31 +1235,34 @@ func file_group_proto_rawDescGZIP() []byte { return file_group_proto_rawDescData } -var file_group_proto_msgTypes = make([]protoimpl.MessageInfo, 17) +var file_group_proto_msgTypes = make([]protoimpl.MessageInfo, 20) var file_group_proto_goTypes = []interface{}{ - (*Empty)(nil), // 0: Empty - (*CreateGroupRequest)(nil), // 1: CreateGroupRequest - (*ListElement)(nil), // 2: ListElement - (*CreateGroupResponse)(nil), // 3: CreateGroupResponse - (*GenerateInviteCodeRequest)(nil), // 4: GenerateInviteCodeRequest - (*GenerateInviteCodeResponse)(nil), // 5: GenerateInviteCodeResponse - (*JoinGroupRequest)(nil), // 6: JoinGroupRequest - (*JoinGroupResponse)(nil), // 7: JoinGroupResponse - (*ListJoinedGroupsResponse)(nil), // 8: ListJoinedGroupsResponse - (*Group)(nil), // 9: Group - (*GetGroupMembersRequest)(nil), // 10: GetGroupMembersRequest - (*GetGroupMembersResponse)(nil), // 11: GetGroupMembersResponse - (*GroupMember)(nil), // 12: GroupMember - (*DeleteGroupRequest)(nil), // 13: DeleteGroupRequest - (*DeleteInviteCodeRequest)(nil), // 14: DeleteInviteCodeRequest - (*GetInviteCodeRequest)(nil), // 15: GetInviteCodeRequest - (*GetInviteCodeResponse)(nil), // 16: GetInviteCodeResponse - (*durationpb.Duration)(nil), // 17: google.protobuf.Duration + (*Empty)(nil), // 0: Empty + (*CreateGroupRequest)(nil), // 1: CreateGroupRequest + (*ListElement)(nil), // 2: ListElement + (*CreateGroupResponse)(nil), // 3: CreateGroupResponse + (*GenerateInviteCodeRequest)(nil), // 4: GenerateInviteCodeRequest + (*GenerateInviteCodeResponse)(nil), // 5: GenerateInviteCodeResponse + (*JoinGroupRequest)(nil), // 6: JoinGroupRequest + (*JoinGroupResponse)(nil), // 7: JoinGroupResponse + (*ListJoinedGroupsResponse)(nil), // 8: ListJoinedGroupsResponse + (*Group)(nil), // 9: Group + (*GetGroupMembersRequest)(nil), // 10: GetGroupMembersRequest + (*GetGroupMembersResponse)(nil), // 11: GetGroupMembersResponse + (*GroupMember)(nil), // 12: GroupMember + (*DeleteGroupRequest)(nil), // 13: DeleteGroupRequest + (*DeleteInviteCodeRequest)(nil), // 14: DeleteInviteCodeRequest + (*GetInviteCodeRequest)(nil), // 15: GetInviteCodeRequest + (*GetInviteCodeResponse)(nil), // 16: GetInviteCodeResponse + (*GetGroupInfoRequest)(nil), // 17: GetGroupInfoRequest + (*GetGroupInfoResponse)(nil), // 18: GetGroupInfoResponse + (*GetGroupByInviteCodeRequest)(nil), // 19: GetGroupByInviteCodeRequest + (*durationpb.Duration)(nil), // 20: google.protobuf.Duration } var file_group_proto_depIdxs = []int32{ 9, // 0: ListJoinedGroupsResponse.groups:type_name -> Group 12, // 1: GetGroupMembersResponse.members:type_name -> GroupMember - 17, // 2: GetInviteCodeResponse.expires_after:type_name -> google.protobuf.Duration + 20, // 2: GetInviteCodeResponse.expires_after:type_name -> google.protobuf.Duration 1, // 3: GroupService.CreateGroup:input_type -> CreateGroupRequest 0, // 4: GroupService.ListJoinedGroups:input_type -> Empty 4, // 5: GroupService.GenerateInviteCode:input_type -> GenerateInviteCodeRequest @@ -1074,16 +1271,20 @@ var file_group_proto_depIdxs = []int32{ 13, // 8: GroupService.DeleteGroup:input_type -> DeleteGroupRequest 14, // 9: GroupService.DeleteInviteCode:input_type -> DeleteInviteCodeRequest 15, // 10: GroupService.GetInviteCode:input_type -> GetInviteCodeRequest - 3, // 11: GroupService.CreateGroup:output_type -> CreateGroupResponse - 8, // 12: GroupService.ListJoinedGroups:output_type -> ListJoinedGroupsResponse - 5, // 13: GroupService.GenerateInviteCode:output_type -> GenerateInviteCodeResponse - 7, // 14: GroupService.JoinGroup:output_type -> JoinGroupResponse - 11, // 15: GroupService.GetGroupMembers:output_type -> GetGroupMembersResponse - 0, // 16: GroupService.DeleteGroup:output_type -> Empty - 0, // 17: GroupService.DeleteInviteCode:output_type -> Empty - 16, // 18: GroupService.GetInviteCode:output_type -> GetInviteCodeResponse - 11, // [11:19] is the sub-list for method output_type - 3, // [3:11] is the sub-list for method input_type + 17, // 11: GroupService.GetGroupInfo:input_type -> GetGroupInfoRequest + 19, // 12: GroupService.GetGroupByInviteCode:input_type -> GetGroupByInviteCodeRequest + 3, // 13: GroupService.CreateGroup:output_type -> CreateGroupResponse + 8, // 14: GroupService.ListJoinedGroups:output_type -> ListJoinedGroupsResponse + 5, // 15: GroupService.GenerateInviteCode:output_type -> GenerateInviteCodeResponse + 7, // 16: GroupService.JoinGroup:output_type -> JoinGroupResponse + 11, // 17: GroupService.GetGroupMembers:output_type -> GetGroupMembersResponse + 0, // 18: GroupService.DeleteGroup:output_type -> Empty + 0, // 19: GroupService.DeleteInviteCode:output_type -> Empty + 16, // 20: GroupService.GetInviteCode:output_type -> GetInviteCodeResponse + 18, // 21: GroupService.GetGroupInfo:output_type -> GetGroupInfoResponse + 18, // 22: GroupService.GetGroupByInviteCode:output_type -> GetGroupInfoResponse + 13, // [13:23] is the sub-list for method output_type + 3, // [3:13] 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 @@ -1299,6 +1500,42 @@ func file_group_proto_init() { return nil } } + file_group_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetGroupInfoRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_group_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetGroupInfoResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_group_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetGroupByInviteCodeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1306,7 +1543,7 @@ func file_group_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_group_proto_rawDesc, NumEnums: 0, - NumMessages: 17, + NumMessages: 20, NumExtensions: 0, NumServices: 1, }, diff --git a/protobuf/gen/go/group.pb.gw.go b/protobuf/gen/go/group.pb.gw.go index 27be609..d6e8120 100644 --- a/protobuf/gen/go/group.pb.gw.go +++ b/protobuf/gen/go/group.pb.gw.go @@ -335,6 +335,110 @@ func local_request_GroupService_GetInviteCode_0(ctx context.Context, marshaler r } +func request_GroupService_GetGroupInfo_0(ctx context.Context, marshaler runtime.Marshaler, client GroupServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetGroupInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["group_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "group_id") + } + + protoReq.GroupId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "group_id", err) + } + + msg, err := client.GetGroupInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_GroupService_GetGroupInfo_0(ctx context.Context, marshaler runtime.Marshaler, server GroupServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetGroupInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["group_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "group_id") + } + + protoReq.GroupId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "group_id", err) + } + + msg, err := server.GetGroupInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_GroupService_GetGroupByInviteCode_0(ctx context.Context, marshaler runtime.Marshaler, client GroupServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetGroupByInviteCodeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["invite_code"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "invite_code") + } + + protoReq.InviteCode, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "invite_code", err) + } + + msg, err := client.GetGroupByInviteCode(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_GroupService_GetGroupByInviteCode_0(ctx context.Context, marshaler runtime.Marshaler, server GroupServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetGroupByInviteCodeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["invite_code"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "invite_code") + } + + protoReq.InviteCode, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "invite_code", err) + } + + msg, err := server.GetGroupByInviteCode(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterGroupServiceHandlerServer registers the http handlers for service GroupService to "mux". // UnaryRPC :call GroupServiceServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -524,7 +628,7 @@ func RegisterGroupServiceHandlerServer(ctx context.Context, mux *runtime.ServeMu inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) var err error var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.GroupService/GetInviteCode", runtime.WithHTTPPathPattern("/v1/group/invite-code/{group_id}")) + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.GroupService/GetInviteCode", runtime.WithHTTPPathPattern("/v1/group/invite-code/g2i/{group_id}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -541,6 +645,56 @@ func RegisterGroupServiceHandlerServer(ctx context.Context, mux *runtime.ServeMu }) + mux.Handle("GET", pattern_GroupService_GetGroupInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.GroupService/GetGroupInfo", runtime.WithHTTPPathPattern("/v1/group/{group_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_GroupService_GetGroupInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GroupService_GetGroupInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_GroupService_GetGroupByInviteCode_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.GroupService/GetGroupByInviteCode", runtime.WithHTTPPathPattern("/v1/group/invite-code/i2g/{invite_code}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_GroupService_GetGroupByInviteCode_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GroupService_GetGroupByInviteCode_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -742,7 +896,7 @@ func RegisterGroupServiceHandlerClient(ctx context.Context, mux *runtime.ServeMu inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) var err error var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.GroupService/GetInviteCode", runtime.WithHTTPPathPattern("/v1/group/invite-code/{group_id}")) + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.GroupService/GetInviteCode", runtime.WithHTTPPathPattern("/v1/group/invite-code/g2i/{group_id}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -758,6 +912,50 @@ func RegisterGroupServiceHandlerClient(ctx context.Context, mux *runtime.ServeMu }) + mux.Handle("GET", pattern_GroupService_GetGroupInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.GroupService/GetGroupInfo", runtime.WithHTTPPathPattern("/v1/group/{group_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_GroupService_GetGroupInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GroupService_GetGroupInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_GroupService_GetGroupByInviteCode_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.GroupService/GetGroupByInviteCode", runtime.WithHTTPPathPattern("/v1/group/invite-code/i2g/{invite_code}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_GroupService_GetGroupByInviteCode_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GroupService_GetGroupByInviteCode_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -776,7 +974,11 @@ var ( pattern_GroupService_DeleteInviteCode_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "group", "invite-code", "group_id"}, "")) - pattern_GroupService_GetInviteCode_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "group", "invite-code", "group_id"}, "")) + pattern_GroupService_GetInviteCode_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "group", "invite-code", "g2i", "group_id"}, "")) + + pattern_GroupService_GetGroupInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "group", "group_id"}, "")) + + pattern_GroupService_GetGroupByInviteCode_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "group", "invite-code", "i2g", "invite_code"}, "")) ) var ( @@ -795,4 +997,8 @@ var ( forward_GroupService_DeleteInviteCode_0 = runtime.ForwardResponseMessage forward_GroupService_GetInviteCode_0 = runtime.ForwardResponseMessage + + forward_GroupService_GetGroupInfo_0 = runtime.ForwardResponseMessage + + forward_GroupService_GetGroupByInviteCode_0 = runtime.ForwardResponseMessage ) diff --git a/protobuf/gen/go/group_grpc.pb.go b/protobuf/gen/go/group_grpc.pb.go index 9394ba8..955f21b 100644 --- a/protobuf/gen/go/group_grpc.pb.go +++ b/protobuf/gen/go/group_grpc.pb.go @@ -19,14 +19,16 @@ import ( const _ = grpc.SupportPackageIsVersion7 const ( - GroupService_CreateGroup_FullMethodName = "/GroupService/CreateGroup" - GroupService_ListJoinedGroups_FullMethodName = "/GroupService/ListJoinedGroups" - GroupService_GenerateInviteCode_FullMethodName = "/GroupService/GenerateInviteCode" - GroupService_JoinGroup_FullMethodName = "/GroupService/JoinGroup" - GroupService_GetGroupMembers_FullMethodName = "/GroupService/GetGroupMembers" - GroupService_DeleteGroup_FullMethodName = "/GroupService/DeleteGroup" - GroupService_DeleteInviteCode_FullMethodName = "/GroupService/DeleteInviteCode" - GroupService_GetInviteCode_FullMethodName = "/GroupService/GetInviteCode" + GroupService_CreateGroup_FullMethodName = "/GroupService/CreateGroup" + GroupService_ListJoinedGroups_FullMethodName = "/GroupService/ListJoinedGroups" + GroupService_GenerateInviteCode_FullMethodName = "/GroupService/GenerateInviteCode" + GroupService_JoinGroup_FullMethodName = "/GroupService/JoinGroup" + GroupService_GetGroupMembers_FullMethodName = "/GroupService/GetGroupMembers" + GroupService_DeleteGroup_FullMethodName = "/GroupService/DeleteGroup" + GroupService_DeleteInviteCode_FullMethodName = "/GroupService/DeleteInviteCode" + GroupService_GetInviteCode_FullMethodName = "/GroupService/GetInviteCode" + GroupService_GetGroupInfo_FullMethodName = "/GroupService/GetGroupInfo" + GroupService_GetGroupByInviteCode_FullMethodName = "/GroupService/GetGroupByInviteCode" ) // GroupServiceClient is the client API for GroupService service. @@ -41,6 +43,8 @@ type GroupServiceClient interface { DeleteGroup(ctx context.Context, in *DeleteGroupRequest, opts ...grpc.CallOption) (*Empty, error) DeleteInviteCode(ctx context.Context, in *DeleteInviteCodeRequest, opts ...grpc.CallOption) (*Empty, error) GetInviteCode(ctx context.Context, in *GetInviteCodeRequest, opts ...grpc.CallOption) (*GetInviteCodeResponse, error) + GetGroupInfo(ctx context.Context, in *GetGroupInfoRequest, opts ...grpc.CallOption) (*GetGroupInfoResponse, error) + GetGroupByInviteCode(ctx context.Context, in *GetGroupByInviteCodeRequest, opts ...grpc.CallOption) (*GetGroupInfoResponse, error) } type groupServiceClient struct { @@ -123,6 +127,24 @@ func (c *groupServiceClient) GetInviteCode(ctx context.Context, in *GetInviteCod return out, nil } +func (c *groupServiceClient) GetGroupInfo(ctx context.Context, in *GetGroupInfoRequest, opts ...grpc.CallOption) (*GetGroupInfoResponse, error) { + out := new(GetGroupInfoResponse) + err := c.cc.Invoke(ctx, GroupService_GetGroupInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *groupServiceClient) GetGroupByInviteCode(ctx context.Context, in *GetGroupByInviteCodeRequest, opts ...grpc.CallOption) (*GetGroupInfoResponse, error) { + out := new(GetGroupInfoResponse) + err := c.cc.Invoke(ctx, GroupService_GetGroupByInviteCode_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // GroupServiceServer is the server API for GroupService service. // All implementations must embed UnimplementedGroupServiceServer // for forward compatibility @@ -135,6 +157,8 @@ type GroupServiceServer interface { DeleteGroup(context.Context, *DeleteGroupRequest) (*Empty, error) DeleteInviteCode(context.Context, *DeleteInviteCodeRequest) (*Empty, error) GetInviteCode(context.Context, *GetInviteCodeRequest) (*GetInviteCodeResponse, error) + GetGroupInfo(context.Context, *GetGroupInfoRequest) (*GetGroupInfoResponse, error) + GetGroupByInviteCode(context.Context, *GetGroupByInviteCodeRequest) (*GetGroupInfoResponse, error) mustEmbedUnimplementedGroupServiceServer() } @@ -166,6 +190,12 @@ func (UnimplementedGroupServiceServer) DeleteInviteCode(context.Context, *Delete func (UnimplementedGroupServiceServer) GetInviteCode(context.Context, *GetInviteCodeRequest) (*GetInviteCodeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetInviteCode not implemented") } +func (UnimplementedGroupServiceServer) GetGroupInfo(context.Context, *GetGroupInfoRequest) (*GetGroupInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetGroupInfo not implemented") +} +func (UnimplementedGroupServiceServer) GetGroupByInviteCode(context.Context, *GetGroupByInviteCodeRequest) (*GetGroupInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetGroupByInviteCode not implemented") +} func (UnimplementedGroupServiceServer) mustEmbedUnimplementedGroupServiceServer() {} // UnsafeGroupServiceServer may be embedded to opt out of forward compatibility for this service. @@ -323,6 +353,42 @@ func _GroupService_GetInviteCode_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } +func _GroupService_GetGroupInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetGroupInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GroupServiceServer).GetGroupInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: GroupService_GetGroupInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GroupServiceServer).GetGroupInfo(ctx, req.(*GetGroupInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _GroupService_GetGroupByInviteCode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetGroupByInviteCodeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GroupServiceServer).GetGroupByInviteCode(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: GroupService_GetGroupByInviteCode_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GroupServiceServer).GetGroupByInviteCode(ctx, req.(*GetGroupByInviteCodeRequest)) + } + return interceptor(ctx, in, info, handler) +} + // GroupService_ServiceDesc is the grpc.ServiceDesc for GroupService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -362,6 +428,14 @@ var GroupService_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetInviteCode", Handler: _GroupService_GetInviteCode_Handler, }, + { + MethodName: "GetGroupInfo", + Handler: _GroupService_GetGroupInfo_Handler, + }, + { + MethodName: "GetGroupByInviteCode", + Handler: _GroupService_GetGroupByInviteCode_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "group.proto", diff --git a/protobuf/group.proto b/protobuf/group.proto index 92cf033..e4600a7 100644 --- a/protobuf/group.proto +++ b/protobuf/group.proto @@ -45,6 +45,8 @@ service GroupService{ }; } + + rpc GetGroupMembers(GetGroupMembersRequest) returns (GetGroupMembersResponse) { option (google.api.http) = { get: "/v1/group/members/{group_id}" @@ -65,7 +67,19 @@ service GroupService{ rpc GetInviteCode(GetInviteCodeRequest) returns (GetInviteCodeResponse) { option (google.api.http) = { - get: "/v1/group/invite-code/{group_id}" + get: "/v1/group/invite-code/g2i/{group_id}" + }; + } + + rpc GetGroupInfo(GetGroupInfoRequest) returns (GetGroupInfoResponse) { + option (google.api.http) = { + get: "/v1/group/{group_id}" + }; + } + + rpc GetGroupByInviteCode(GetGroupByInviteCodeRequest) returns (GetGroupInfoResponse) { + option (google.api.http) = { + get: "/v1/group/invite-code/i2g/{invite_code}" }; } @@ -148,4 +162,19 @@ message GetInviteCodeRequest{ message GetInviteCodeResponse{ string invite_code = 1; google.protobuf.Duration expires_after = 2; -} \ No newline at end of file +} + +message GetGroupInfoRequest{ + string group_id = 1; +} + +message GetGroupInfoResponse{ + string group_id = 1; + string name = 2; + string description = 3; + string avatar_url = 4; +} + +message GetGroupByInviteCodeRequest{ + string invite_code = 1; +} diff --git a/services/api/controllers/group/create.go b/services/api/controllers/group/create.go index d5bfaaa..f42e175 100644 --- a/services/api/controllers/group/create.go +++ b/services/api/controllers/group/create.go @@ -13,11 +13,11 @@ import ( "google.golang.org/grpc/status" ) -func createGroup(ctx context.Context, tx *sql.Tx, name string) (uuid.UUID, error) { +func createGroup(ctx context.Context, tx *sql.Tx, name string, description string) (uuid.UUID, error) { groupId := uuid.New() _, err := tx.ExecContext(ctx, ` - INSERT INTO "group" (group_id, name) VALUES ($1, $2) - `, groupId, name) + INSERT INTO "group" (group_id, name, description) VALUES ($1, $2, $3) + `, groupId, name, description) return groupId, err } @@ -42,7 +42,7 @@ func (s Service) CreateGroup(ctx context.Context, req *monify.CreateGroupRequest defer tx.Rollback() var groupId uuid.UUID - if groupId, err = createGroup(ctx, tx, groupName); err != nil { + if groupId, err = createGroup(ctx, tx, groupName, req.Description); err != nil { logger.Error("", zap.Error(err)) return nil, status.Error(codes.Internal, "internal") } diff --git a/services/api/controllers/group/get_group.go b/services/api/controllers/group/get_group.go new file mode 100644 index 0000000..1a66209 --- /dev/null +++ b/services/api/controllers/group/get_group.go @@ -0,0 +1,73 @@ +package group + +import ( + "context" + "database/sql" + "github.com/google/uuid" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "monify/lib" + monify "monify/protobuf/gen/go" +) + +func (s Service) GetGroupInfo(ctx context.Context, req *monify.GetGroupInfoRequest) (*monify.GetGroupInfoResponse, error) { + userId, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID) + if !ok { + return nil, status.Error(codes.Unauthenticated, "Unauthorized.") + } + groupId, err := uuid.Parse(req.GroupId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "Invalid group ID") + } + hasPerm, err := CheckPermission(ctx, groupId, userId) + if err != nil { + return nil, status.Error(codes.Internal, "Internal") + } + if !hasPerm { + return nil, status.Error(codes.PermissionDenied, "Permission denied") + } + + return GetGroupInfo(ctx, groupId) +} + +func (s Service) GetGroupByInviteCode(ctx context.Context, req *monify.GetGroupByInviteCodeRequest) (*monify.GetGroupInfoResponse, error) { + _, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID) + if !ok { + return nil, status.Error(codes.Unauthenticated, "Unauthorized.") + } + + db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB) + logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger) + + var groupId uuid.UUID + err := db.QueryRowContext(ctx, "SELECT group_id FROM group_invite_code WHERE invite_code = $1", req.InviteCode).Scan(&groupId) + if err != nil { + if err == sql.ErrNoRows { + return nil, status.Error(codes.NotFound, "Group not found") + } + logger.Error("Failed to get group by invite code", zap.Error(err)) + return nil, status.Error(codes.Internal, "Internal") + } + + return GetGroupInfo(ctx, groupId) +} + +func GetGroupInfo(ctx context.Context, groupId uuid.UUID) (*monify.GetGroupInfoResponse, error) { + db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB) + logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger) + + response := &monify.GetGroupInfoResponse{ + GroupId: groupId.String(), + } + err := db.QueryRowContext(ctx, "SELECT name, description, avatar_url FROM 'group' WHERE group_id = $1", groupId).Scan(&response.Name, &response.Description, &response.AvatarUrl) + if err != nil { + if err == sql.ErrNoRows { + return nil, status.Error(codes.NotFound, "Group not found") + } + logger.Error("Failed to get group info", zap.Error(err)) + return nil, status.Error(codes.Internal, "Internal") + } + + return response, nil +} diff --git a/services/api/controllers/group/list_joined.go b/services/api/controllers/group/list_joined.go index 6eaddf6..9cd49bf 100644 --- a/services/api/controllers/group/list_joined.go +++ b/services/api/controllers/group/list_joined.go @@ -20,7 +20,7 @@ func (s Service) ListJoinedGroups(ctx context.Context, _ *monify.Empty) (*monify db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB) query, err := db.QueryContext(ctx, ` - SELECT "group".group_id, "group".name + SELECT "group".group_id, "group".name, "group".description FROM "group" JOIN group_member ON "group".group_id = group_member.group_id WHERE user_id = $1 AND is_deleted = false`, userId) if err != nil { @@ -35,7 +35,7 @@ func (s Service) ListJoinedGroups(ctx context.Context, _ *monify.Empty) (*monify break } var group monify.Group - if err = query.Scan(&group.GroupId, &group.Name); err != nil { + if err = query.Scan(&group.GroupId, &group.Name, &group.Description); err != nil { logger.Error("scan group_id error", zap.Error(err)) return nil, status.Error(codes.Internal, "") } diff --git a/services/api/server.go b/services/api/server.go index 87cae53..6642768 100644 --- a/services/api/server.go +++ b/services/api/server.go @@ -15,6 +15,7 @@ import ( "monify/services/api/controllers/group_bill" "monify/services/api/infra" "net" + "time" ) type Server struct { @@ -56,10 +57,13 @@ func setupInterceptor(resources infra.Resources, config ServerConfig) grpc.Serve ctx = context.WithValue(ctx, lib.UserIdContextKey{}, userId) } requestId := uuid.New() + logger := resources.Logger.With(zap.String("request_id", requestId.String())) ctx = context.WithValue(ctx, lib.KafkaWriterContextKey{}, resources.KafkaWriters) ctx = context.WithValue(ctx, lib.DatabaseContextKey{}, resources.DBConn) - ctx = context.WithValue(ctx, lib.LoggerContextKey{}, resources.Logger.With(zap.String("request_id", requestId.String()))) + ctx = context.WithValue(ctx, lib.LoggerContextKey{}, logger) + start := time.Now() m, err := handler(ctx, req) + logger.Log(zap.InfoLevel, "request completed", zap.Duration("duration", time.Since(start)), zap.String("method", info.FullMethod)) return m, err } return grpc.UnaryInterceptor(interceptor) diff --git a/services/api/test/group_test.go b/services/api/test/group_test.go index 2085402..7158be9 100644 --- a/services/api/test/group_test.go +++ b/services/api/test/group_test.go @@ -2,16 +2,15 @@ package test import ( "context" + "github.com/stretchr/testify/assert" monify "monify/protobuf/gen/go" "testing" - - "github.com/stretchr/testify/assert" ) func TestCreateGroup(t *testing.T) { client := GetTestClient(t) _ = client.CreateTestUser() - group, err := client.CreateGroup(context.Background(), &monify.CreateGroupRequest{Name: "test"}) + group, err := client.CreateGroup(context.Background(), &monify.CreateGroupRequest{Name: "test", Description: "cool desc"}) assert.NoError(t, err) assert.NotEmpty(t, group) code, err := client.GenerateInviteCode(context.TODO(), &monify.GenerateInviteCodeRequest{GroupId: group.GroupId}) @@ -24,6 +23,8 @@ func TestCreateGroup(t *testing.T) { groups, err := client.ListJoinedGroups(context.TODO(), &monify.Empty{}) assert.NoError(t, err) assert.Equal(t, joinGroup.GetGroupId(), groups.Groups[0].GroupId) + assert.Equal(t, "test", groups.Groups[0].Name) + assert.Equal(t, "cool desc", groups.Groups[0].Description) client.CreateTestUser() _, err = client.DeleteGroup(context.TODO(), &monify.DeleteGroupRequest{GroupId: group.GroupId}) @@ -32,6 +33,8 @@ func TestCreateGroup(t *testing.T) { groups, err = client.ListJoinedGroups(context.TODO(), &monify.Empty{}) assert.NoError(t, err) assert.Equal(t, joinGroup.GetGroupId(), groups.Groups[0].GroupId) + assert.Equal(t, "test", groups.Groups[0].Name) + assert.Equal(t, "cool desc", groups.Groups[0].Description) _, err = client.DeleteGroup(context.TODO(), &monify.DeleteGroupRequest{GroupId: group.GroupId}) assert.NoError(t, err) @@ -43,7 +46,7 @@ func TestCreateGroup(t *testing.T) { func TestGroupInviteCode(t *testing.T) { client := GetTestClient(t) _ = client.CreateTestUser() - group, err := client.CreateGroup(context.Background(), &monify.CreateGroupRequest{Name: "test"}) + group, err := client.CreateGroup(context.Background(), &monify.CreateGroupRequest{Name: "test", Description: "test123"}) assert.NoError(t, err) assert.NotEmpty(t, group) code, err := client.GenerateInviteCode(context.Background(), &monify.GenerateInviteCodeRequest{GroupId: group.GroupId}) @@ -53,6 +56,18 @@ func TestGroupInviteCode(t *testing.T) { assert.NoError(t, err) assert.Equal(t, code.InviteCode, inviteCode.InviteCode) + groupBrief, err := client.GetGroupByInviteCode(context.Background(), &monify.GetGroupByInviteCodeRequest{InviteCode: code.InviteCode}) + assert.NoError(t, err) + assert.Equal(t, group.GroupId, groupBrief.GroupId) + assert.Equal(t, "test", groupBrief.Name) + assert.Equal(t, "test123", groupBrief.Description) + + groupBrief, err = client.GetGroupInfo(context.Background(), &monify.GetGroupInfoRequest{GroupId: group.GroupId}) + assert.NoError(t, err) + assert.Equal(t, group.GroupId, groupBrief.GroupId) + assert.Equal(t, "test", groupBrief.Name) + assert.Equal(t, "test123", groupBrief.Description) + _, err = client.DeleteInviteCode(context.Background(), &monify.DeleteInviteCodeRequest{GroupId: group.GroupId}) assert.NoError(t, err) inviteCode, err = client.GetInviteCode(context.Background(), &monify.GetInviteCodeRequest{GroupId: group.GroupId}) diff --git a/services/media/api_test.go b/services/media/api_test.go new file mode 100644 index 0000000..725ca06 --- /dev/null +++ b/services/media/api_test.go @@ -0,0 +1,7 @@ +package media + +import "testing" + +func TestW(t *testing.T) { + +} diff --git a/services/media/handler.go b/services/media/handler.go index cd87534..2d16b63 100644 --- a/services/media/handler.go +++ b/services/media/handler.go @@ -98,7 +98,11 @@ func uploadImage(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - w.Write(resBody) + _, err = w.Write(resBody) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } diff --git a/services/media/infra.go b/services/media/infra.go index 1e3c636..fbf504b 100644 --- a/services/media/infra.go +++ b/services/media/infra.go @@ -8,6 +8,7 @@ import ( type Infra struct { db *sql.DB objStorage S3ImageStorage + config Config } func Setup(config Config) (Infra, error) { @@ -20,6 +21,8 @@ func Setup(config Config) (Infra, error) { } return Infra{ - db: db, + db: db, + config: config, + objStorage: NewS3ImageStorage(config), }, nil } diff --git a/services/media/instance.go b/services/media/instance.go index 170a590..a869db9 100644 --- a/services/media/instance.go +++ b/services/media/instance.go @@ -1,15 +1,47 @@ package media import ( + "context" + "fmt" "log" + "monify/lib" "monify/lib/auth" + "net" "net/http" ) -func Start(config Config) { +type Server struct { + mux *http.ServeMux +} - authMiddleware := auth.AuthMiddleware{JwtSecret: config.JwtSecret} - http.Handle("/image", authMiddleware.HttpMiddleware(http.HandlerFunc(uploadImage))) +func NewServer(infra Infra) Server { + mux := http.NewServeMux() + authMiddleware := auth.AuthMiddleware{JwtSecret: infra.config.JwtSecret} + resourceMiddleware := func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + ctx = context.WithValue(ctx, lib.ImageStorageContextKey{}, infra.objStorage) + ctx = context.WithValue(ctx, lib.DatabaseContextKey{}, infra.db) + ctx = context.WithValue(ctx, lib.ConfigContextKey{}, infra.config) + next.ServeHTTP(w, r.WithContext(ctx)) + }) + } + mux.Handle("/image", resourceMiddleware(authMiddleware.HttpMiddleware(http.HandlerFunc(uploadImage)))) + return Server{ + mux: mux, + } +} - log.Fatal(http.ListenAndServe(":8080", nil)) +func (s Server) Start() { + port := "8080" + //start listening + lis, err := net.Listen("tcp", fmt.Sprintf(":%s", port)) + if err != nil { + panic(err) + } + err = http.Serve(lis, s.mux) + if err != nil { + return + } + log.Fatal(http.ListenAndServe(":"+port, nil)) }