From c3ae8ee9194e6df1db4a1c5d965b3efa9c2bc8d5 Mon Sep 17 00:00:00 2001 From: Juan Peredo Date: Sat, 30 May 2020 19:45:50 -0500 Subject: [PATCH] Added email and company to user --- user/client/userClient.go | 5 + user/proto/user.pb.go | 365 ++++++++++++++++------ user/proto/user.pb.micro.go | 34 ++ user/proto/user.proto | 14 + user/server/handler.go | 68 +++- user/server/handler_test.go | 6 +- user/server/statements/errorstatements.go | 12 + 7 files changed, 401 insertions(+), 103 deletions(-) diff --git a/user/client/userClient.go b/user/client/userClient.go index 5638ef9..f60923b 100644 --- a/user/client/userClient.go +++ b/user/client/userClient.go @@ -30,6 +30,8 @@ func CreateUser(srvClient pb.UserSrvService) (*pb.User, error) { ValidThru: validThru, Active: true, Pwd: "1234", + Email: "microbes@tiny.com", + Company: "Tiny", } //if serverAddress != "" { @@ -57,6 +59,8 @@ func UpdateUser(srvClient pb.UserSrvService, user *pb.User) (*pb.User, error) { user.ValidThru = validThru user.Active = false user.Pwd = "5678" + user.Email = "microbes@tiny.com" + user.Company = "Tiny" //if serverAddress != "" { //outUser, err = srvClient.UpdateUser(context.Background(), user, client.WithAddress(serverAddress)) @@ -120,6 +124,7 @@ func GetUsers(srvClient pb.UserSrvService) (*pb.Users, error) { Fisrtname: "Super", Lastname: "Duck", ValidDate: searchDate, + Email: "duck@mymail.com", } var outUsers *pb.Users diff --git a/user/proto/user.pb.go b/user/proto/user.pb.go index 1132681..a85716b 100644 --- a/user/proto/user.pb.go +++ b/user/proto/user.pb.go @@ -201,6 +201,9 @@ type SearchParams struct { Fisrtname string `protobuf:"bytes,2,opt,name=fisrtname,proto3" json:"fisrtname,omitempty"` Lastname string `protobuf:"bytes,3,opt,name=lastname,proto3" json:"lastname,omitempty"` ValidDate *timestamp.Timestamp `protobuf:"bytes,5,opt,name=validDate,proto3" json:"validDate,omitempty"` + Email string `protobuf:"bytes,9,opt,name=email,proto3" json:"email,omitempty"` + Company string `protobuf:"bytes,10,opt,name=company,proto3" json:"company,omitempty"` + Pwd string `protobuf:"bytes,11,opt,name=pwd,proto3" json:"pwd,omitempty"` } func (x *SearchParams) Reset() { @@ -263,6 +266,74 @@ func (x *SearchParams) GetValidDate() *timestamp.Timestamp { return nil } +func (x *SearchParams) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *SearchParams) GetCompany() string { + if x != nil { + return x.Company + } + return "" +} + +func (x *SearchParams) GetPwd() string { + if x != nil { + return x.Pwd + } + return "" +} + +type SearchString struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *SearchString) Reset() { + *x = SearchString{} + if protoimpl.UnsafeEnabled { + mi := &file_user_proto_user_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SearchString) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchString) ProtoMessage() {} + +func (x *SearchString) ProtoReflect() protoreflect.Message { + mi := &file_user_proto_user_proto_msgTypes[3] + 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 SearchString.ProtoReflect.Descriptor instead. +func (*SearchString) Descriptor() ([]byte, []int) { + return file_user_proto_user_proto_rawDescGZIP(), []int{3} +} + +func (x *SearchString) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + type SearchId struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -274,7 +345,7 @@ type SearchId struct { func (x *SearchId) Reset() { *x = SearchId{} if protoimpl.UnsafeEnabled { - mi := &file_user_proto_user_proto_msgTypes[3] + mi := &file_user_proto_user_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -287,7 +358,7 @@ func (x *SearchId) String() string { func (*SearchId) ProtoMessage() {} func (x *SearchId) ProtoReflect() protoreflect.Message { - mi := &file_user_proto_user_proto_msgTypes[3] + mi := &file_user_proto_user_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -300,7 +371,7 @@ func (x *SearchId) ProtoReflect() protoreflect.Message { // Deprecated: Use SearchId.ProtoReflect.Descriptor instead. func (*SearchId) Descriptor() ([]byte, []int) { - return file_user_proto_user_proto_rawDescGZIP(), []int{3} + return file_user_proto_user_proto_rawDescGZIP(), []int{4} } func (x *SearchId) GetId() int64 { @@ -321,7 +392,7 @@ type AffectedCount struct { func (x *AffectedCount) Reset() { *x = AffectedCount{} if protoimpl.UnsafeEnabled { - mi := &file_user_proto_user_proto_msgTypes[4] + mi := &file_user_proto_user_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -334,7 +405,7 @@ func (x *AffectedCount) String() string { func (*AffectedCount) ProtoMessage() {} func (x *AffectedCount) ProtoReflect() protoreflect.Message { - mi := &file_user_proto_user_proto_msgTypes[4] + mi := &file_user_proto_user_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -347,7 +418,7 @@ func (x *AffectedCount) ProtoReflect() protoreflect.Message { // Deprecated: Use AffectedCount.ProtoReflect.Descriptor instead. func (*AffectedCount) Descriptor() ([]byte, []int) { - return file_user_proto_user_proto_rawDescGZIP(), []int{4} + return file_user_proto_user_proto_rawDescGZIP(), []int{5} } func (x *AffectedCount) GetValue() int64 { @@ -368,7 +439,7 @@ type ValidationErr struct { func (x *ValidationErr) Reset() { *x = ValidationErr{} if protoimpl.UnsafeEnabled { - mi := &file_user_proto_user_proto_msgTypes[5] + mi := &file_user_proto_user_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -381,7 +452,7 @@ func (x *ValidationErr) String() string { func (*ValidationErr) ProtoMessage() {} func (x *ValidationErr) ProtoReflect() protoreflect.Message { - mi := &file_user_proto_user_proto_msgTypes[5] + mi := &file_user_proto_user_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -394,7 +465,7 @@ func (x *ValidationErr) ProtoReflect() protoreflect.Message { // Deprecated: Use ValidationErr.ProtoReflect.Descriptor instead. func (*ValidationErr) Descriptor() ([]byte, []int) { - return file_user_proto_user_proto_rawDescGZIP(), []int{5} + return file_user_proto_user_proto_rawDescGZIP(), []int{6} } func (x *ValidationErr) GetFailureDesc() []string { @@ -415,7 +486,7 @@ type AfterFuncErr struct { func (x *AfterFuncErr) Reset() { *x = AfterFuncErr{} if protoimpl.UnsafeEnabled { - mi := &file_user_proto_user_proto_msgTypes[6] + mi := &file_user_proto_user_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -428,7 +499,7 @@ func (x *AfterFuncErr) String() string { func (*AfterFuncErr) ProtoMessage() {} func (x *AfterFuncErr) ProtoReflect() protoreflect.Message { - mi := &file_user_proto_user_proto_msgTypes[6] + mi := &file_user_proto_user_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -441,7 +512,7 @@ func (x *AfterFuncErr) ProtoReflect() protoreflect.Message { // Deprecated: Use AfterFuncErr.ProtoReflect.Descriptor instead. func (*AfterFuncErr) Descriptor() ([]byte, []int) { - return file_user_proto_user_proto_rawDescGZIP(), []int{6} + return file_user_proto_user_proto_rawDescGZIP(), []int{7} } func (x *AfterFuncErr) GetFailureDesc() []string { @@ -451,6 +522,61 @@ func (x *AfterFuncErr) GetFailureDesc() []string { return nil } +type Token struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + Valid bool `protobuf:"varint,2,opt,name=valid,proto3" json:"valid,omitempty"` +} + +func (x *Token) Reset() { + *x = Token{} + if protoimpl.UnsafeEnabled { + mi := &file_user_proto_user_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Token) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Token) ProtoMessage() {} + +func (x *Token) ProtoReflect() protoreflect.Message { + mi := &file_user_proto_user_proto_msgTypes[8] + 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 Token.ProtoReflect.Descriptor instead. +func (*Token) Descriptor() ([]byte, []int) { + return file_user_proto_user_proto_rawDescGZIP(), []int{8} +} + +func (x *Token) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *Token) GetValid() bool { + if x != nil { + return x.Valid + } + return false +} + var File_user_proto_user_proto protoreflect.FileDescriptor var file_user_proto_user_proto_rawDesc = []byte{ @@ -479,7 +605,7 @@ var file_user_proto_user_proto_rawDesc = []byte{ 0x70, 0x61, 0x6e, 0x79, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x22, 0x27, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x12, 0x1e, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x92, 0x01, 0x0a, + 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0xd4, 0x01, 0x0a, 0x0c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x69, 0x73, 0x72, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, @@ -489,54 +615,69 @@ var file_user_proto_user_proto_rawDesc = []byte{ 0x44, 0x61, 0x74, 0x65, 0x18, 0x05, 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, 0x09, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x44, 0x61, 0x74, - 0x65, 0x22, 0x1a, 0x0a, 0x08, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x49, 0x64, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x25, 0x0a, - 0x0d, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x22, 0x31, 0x0a, 0x0d, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, - 0x44, 0x65, 0x73, 0x63, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x66, 0x61, 0x69, 0x6c, - 0x75, 0x72, 0x65, 0x44, 0x65, 0x73, 0x63, 0x22, 0x30, 0x0a, 0x0c, 0x41, 0x66, 0x74, 0x65, 0x72, - 0x46, 0x75, 0x6e, 0x63, 0x45, 0x72, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x66, 0x61, 0x69, 0x6c, 0x75, - 0x72, 0x65, 0x44, 0x65, 0x73, 0x63, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x66, 0x61, - 0x69, 0x6c, 0x75, 0x72, 0x65, 0x44, 0x65, 0x73, 0x63, 0x32, 0xae, 0x04, 0x0a, 0x07, 0x75, 0x73, - 0x65, 0x72, 0x53, 0x72, 0x76, 0x12, 0x2b, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, - 0x42, 0x79, 0x49, 0x64, 0x12, 0x0e, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, - 0x63, 0x68, 0x49, 0x64, 0x1a, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, - 0x22, 0x00, 0x12, 0x2d, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, 0x12, 0x12, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x1a, 0x0b, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x73, 0x22, - 0x00, 0x12, 0x26, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, - 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x0a, 0x2e, 0x75, 0x73, - 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x0a, 0x55, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, - 0x73, 0x65, 0x72, 0x1a, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x22, - 0x00, 0x12, 0x33, 0x0a, 0x0a, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, - 0x0e, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x49, 0x64, 0x1a, - 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, - 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x10, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x61, - 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x22, 0x00, 0x12, 0x35, 0x0a, - 0x10, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, - 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x13, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, - 0x72, 0x72, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x10, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x0f, 0x41, - 0x66, 0x74, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x72, 0x72, 0x22, 0x00, - 0x12, 0x33, 0x0a, 0x0f, 0x41, 0x66, 0x74, 0x65, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, - 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, - 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x75, 0x6e, 0x63, - 0x45, 0x72, 0x72, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x0f, 0x41, 0x66, 0x74, 0x65, 0x72, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x41, 0x66, 0x74, 0x65, - 0x72, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x72, 0x72, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11, 0x67, 0x6f, - 0x54, 0x65, 0x6d, 0x70, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x70, 0x61, + 0x6e, 0x79, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x77, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x70, 0x77, 0x64, 0x22, 0x24, 0x0a, 0x0c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x53, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x1a, 0x0a, 0x08, 0x53, 0x65, 0x61, + 0x72, 0x63, 0x68, 0x49, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x25, 0x0a, 0x0d, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, + 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x31, 0x0a, 0x0d, + 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x12, 0x20, 0x0a, + 0x0b, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x44, 0x65, 0x73, 0x63, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x0b, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x44, 0x65, 0x73, 0x63, 0x22, + 0x30, 0x0a, 0x0c, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x72, 0x72, 0x12, + 0x20, 0x0a, 0x0b, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x44, 0x65, 0x73, 0x63, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x44, 0x65, 0x73, + 0x63, 0x22, 0x33, 0x0a, 0x05, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x32, 0x87, 0x05, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x53, + 0x72, 0x76, 0x12, 0x2b, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x42, 0x79, 0x49, + 0x64, 0x12, 0x0e, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x49, + 0x64, 0x1a, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x22, 0x00, 0x12, + 0x2d, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, 0x12, 0x12, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, + 0x0b, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x73, 0x22, 0x00, 0x12, 0x34, + 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, 0x42, 0x79, 0x45, 0x6d, 0x61, 0x69, + 0x6c, 0x12, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x53, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x1a, 0x0b, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, + 0x72, 0x73, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, + 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x0a, + 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x0a, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, + 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x0a, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, + 0x65, 0x72, 0x12, 0x0e, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, + 0x49, 0x64, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, + 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x10, 0x42, 0x65, 0x66, + 0x6f, 0x72, 0x65, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, + 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x22, 0x00, + 0x12, 0x35, 0x0a, 0x10, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x10, 0x42, 0x65, 0x66, 0x6f, 0x72, + 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, + 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x22, 0x00, 0x12, 0x33, + 0x0a, 0x0f, 0x41, 0x66, 0x74, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, + 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x12, 0x2e, + 0x75, 0x73, 0x65, 0x72, 0x2e, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x72, + 0x72, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x0f, 0x41, 0x66, 0x74, 0x65, 0x72, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, + 0x75, 0x6e, 0x63, 0x45, 0x72, 0x72, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x0f, 0x41, 0x66, 0x74, 0x65, + 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0a, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x41, + 0x66, 0x74, 0x65, 0x72, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x72, 0x72, 0x22, 0x00, 0x12, 0x21, 0x0a, + 0x04, 0x41, 0x75, 0x74, 0x68, 0x12, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x75, 0x73, 0x65, + 0x72, 0x1a, 0x0b, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x00, + 0x42, 0x13, 0x5a, 0x11, 0x67, 0x6f, 0x54, 0x65, 0x6d, 0x70, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -551,46 +692,52 @@ func file_user_proto_user_proto_rawDescGZIP() []byte { return file_user_proto_user_proto_rawDescData } -var file_user_proto_user_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_user_proto_user_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_user_proto_user_proto_goTypes = []interface{}{ (*User)(nil), // 0: user.user (*Users)(nil), // 1: user.users (*SearchParams)(nil), // 2: user.SearchParams - (*SearchId)(nil), // 3: user.SearchId - (*AffectedCount)(nil), // 4: user.affectedCount - (*ValidationErr)(nil), // 5: user.validationErr - (*AfterFuncErr)(nil), // 6: user.AfterFuncErr - (*timestamp.Timestamp)(nil), // 7: google.protobuf.Timestamp + (*SearchString)(nil), // 3: user.SearchString + (*SearchId)(nil), // 4: user.SearchId + (*AffectedCount)(nil), // 5: user.affectedCount + (*ValidationErr)(nil), // 6: user.validationErr + (*AfterFuncErr)(nil), // 7: user.AfterFuncErr + (*Token)(nil), // 8: user.Token + (*timestamp.Timestamp)(nil), // 9: google.protobuf.Timestamp } var file_user_proto_user_proto_depIdxs = []int32{ - 7, // 0: user.user.validFrom:type_name -> google.protobuf.Timestamp - 7, // 1: user.user.validThru:type_name -> google.protobuf.Timestamp + 9, // 0: user.user.validFrom:type_name -> google.protobuf.Timestamp + 9, // 1: user.user.validThru:type_name -> google.protobuf.Timestamp 0, // 2: user.users.user:type_name -> user.user - 7, // 3: user.SearchParams.validDate:type_name -> google.protobuf.Timestamp - 3, // 4: user.userSrv.GetUserById:input_type -> user.SearchId + 9, // 3: user.SearchParams.validDate:type_name -> google.protobuf.Timestamp + 4, // 4: user.userSrv.GetUserById:input_type -> user.SearchId 2, // 5: user.userSrv.GetUsers:input_type -> user.SearchParams - 0, // 6: user.userSrv.CreateUser:input_type -> user.user - 0, // 7: user.userSrv.UpdateUser:input_type -> user.user - 3, // 8: user.userSrv.DeleteUser:input_type -> user.SearchId - 0, // 9: user.userSrv.BeforeCreateUser:input_type -> user.user - 0, // 10: user.userSrv.BeforeUpdateUser:input_type -> user.user - 0, // 11: user.userSrv.BeforeDeleteUser:input_type -> user.user - 0, // 12: user.userSrv.AfterCreateUser:input_type -> user.user - 0, // 13: user.userSrv.AfterUpdateUser:input_type -> user.user - 0, // 14: user.userSrv.AfterDeleteUser:input_type -> user.user - 0, // 15: user.userSrv.GetUserById:output_type -> user.user - 1, // 16: user.userSrv.GetUsers:output_type -> user.users - 0, // 17: user.userSrv.CreateUser:output_type -> user.user - 0, // 18: user.userSrv.UpdateUser:output_type -> user.user - 4, // 19: user.userSrv.DeleteUser:output_type -> user.affectedCount - 5, // 20: user.userSrv.BeforeCreateUser:output_type -> user.validationErr - 5, // 21: user.userSrv.BeforeUpdateUser:output_type -> user.validationErr - 5, // 22: user.userSrv.BeforeDeleteUser:output_type -> user.validationErr - 6, // 23: user.userSrv.AfterCreateUser:output_type -> user.AfterFuncErr - 6, // 24: user.userSrv.AfterUpdateUser:output_type -> user.AfterFuncErr - 6, // 25: user.userSrv.AfterDeleteUser:output_type -> user.AfterFuncErr - 15, // [15:26] is the sub-list for method output_type - 4, // [4:15] is the sub-list for method input_type + 3, // 6: user.userSrv.GetUsersByEmail:input_type -> user.SearchString + 0, // 7: user.userSrv.CreateUser:input_type -> user.user + 0, // 8: user.userSrv.UpdateUser:input_type -> user.user + 4, // 9: user.userSrv.DeleteUser:input_type -> user.SearchId + 0, // 10: user.userSrv.BeforeCreateUser:input_type -> user.user + 0, // 11: user.userSrv.BeforeUpdateUser:input_type -> user.user + 0, // 12: user.userSrv.BeforeDeleteUser:input_type -> user.user + 0, // 13: user.userSrv.AfterCreateUser:input_type -> user.user + 0, // 14: user.userSrv.AfterUpdateUser:input_type -> user.user + 0, // 15: user.userSrv.AfterDeleteUser:input_type -> user.user + 0, // 16: user.userSrv.Auth:input_type -> user.user + 0, // 17: user.userSrv.GetUserById:output_type -> user.user + 1, // 18: user.userSrv.GetUsers:output_type -> user.users + 1, // 19: user.userSrv.GetUsersByEmail:output_type -> user.users + 0, // 20: user.userSrv.CreateUser:output_type -> user.user + 0, // 21: user.userSrv.UpdateUser:output_type -> user.user + 5, // 22: user.userSrv.DeleteUser:output_type -> user.affectedCount + 6, // 23: user.userSrv.BeforeCreateUser:output_type -> user.validationErr + 6, // 24: user.userSrv.BeforeUpdateUser:output_type -> user.validationErr + 6, // 25: user.userSrv.BeforeDeleteUser:output_type -> user.validationErr + 7, // 26: user.userSrv.AfterCreateUser:output_type -> user.AfterFuncErr + 7, // 27: user.userSrv.AfterUpdateUser:output_type -> user.AfterFuncErr + 7, // 28: user.userSrv.AfterDeleteUser:output_type -> user.AfterFuncErr + 8, // 29: user.userSrv.Auth:output_type -> user.Token + 17, // [17:30] is the sub-list for method output_type + 4, // [4:17] is the sub-list for method input_type 4, // [4:4] is the sub-list for extension type_name 4, // [4:4] is the sub-list for extension extendee 0, // [0:4] is the sub-list for field type_name @@ -639,7 +786,7 @@ func file_user_proto_user_proto_init() { } } file_user_proto_user_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SearchId); i { + switch v := v.(*SearchString); i { case 0: return &v.state case 1: @@ -651,7 +798,7 @@ func file_user_proto_user_proto_init() { } } file_user_proto_user_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AffectedCount); i { + switch v := v.(*SearchId); i { case 0: return &v.state case 1: @@ -663,7 +810,7 @@ func file_user_proto_user_proto_init() { } } file_user_proto_user_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ValidationErr); i { + switch v := v.(*AffectedCount); i { case 0: return &v.state case 1: @@ -675,6 +822,18 @@ func file_user_proto_user_proto_init() { } } file_user_proto_user_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ValidationErr); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_proto_user_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*AfterFuncErr); i { case 0: return &v.state @@ -686,6 +845,18 @@ func file_user_proto_user_proto_init() { return nil } } + file_user_proto_user_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Token); 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{ @@ -693,7 +864,7 @@ func file_user_proto_user_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_user_proto_user_proto_rawDesc, NumEnums: 0, - NumMessages: 7, + NumMessages: 9, NumExtensions: 0, NumServices: 1, }, diff --git a/user/proto/user.pb.micro.go b/user/proto/user.pb.micro.go index 23b8119..7bcae24 100644 --- a/user/proto/user.pb.micro.go +++ b/user/proto/user.pb.micro.go @@ -45,6 +45,7 @@ func NewUserSrvEndpoints() []*api.Endpoint { type UserSrvService interface { GetUserById(ctx context.Context, in *SearchId, opts ...client.CallOption) (*User, error) GetUsers(ctx context.Context, in *SearchParams, opts ...client.CallOption) (*Users, error) + GetUsersByEmail(ctx context.Context, in *SearchString, opts ...client.CallOption) (*Users, error) CreateUser(ctx context.Context, in *User, opts ...client.CallOption) (*User, error) UpdateUser(ctx context.Context, in *User, opts ...client.CallOption) (*User, error) DeleteUser(ctx context.Context, in *SearchId, opts ...client.CallOption) (*AffectedCount, error) @@ -54,6 +55,7 @@ type UserSrvService interface { AfterCreateUser(ctx context.Context, in *User, opts ...client.CallOption) (*AfterFuncErr, error) AfterUpdateUser(ctx context.Context, in *User, opts ...client.CallOption) (*AfterFuncErr, error) AfterDeleteUser(ctx context.Context, in *User, opts ...client.CallOption) (*AfterFuncErr, error) + Auth(ctx context.Context, in *User, opts ...client.CallOption) (*Token, error) } type userSrvService struct { @@ -88,6 +90,16 @@ func (c *userSrvService) GetUsers(ctx context.Context, in *SearchParams, opts .. return out, nil } +func (c *userSrvService) GetUsersByEmail(ctx context.Context, in *SearchString, opts ...client.CallOption) (*Users, error) { + req := c.c.NewRequest(c.name, "UserSrv.GetUsersByEmail", in) + out := new(Users) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *userSrvService) CreateUser(ctx context.Context, in *User, opts ...client.CallOption) (*User, error) { req := c.c.NewRequest(c.name, "UserSrv.CreateUser", in) out := new(User) @@ -178,11 +190,22 @@ func (c *userSrvService) AfterDeleteUser(ctx context.Context, in *User, opts ... return out, nil } +func (c *userSrvService) Auth(ctx context.Context, in *User, opts ...client.CallOption) (*Token, error) { + req := c.c.NewRequest(c.name, "UserSrv.Auth", in) + out := new(Token) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for UserSrv service type UserSrvHandler interface { GetUserById(context.Context, *SearchId, *User) error GetUsers(context.Context, *SearchParams, *Users) error + GetUsersByEmail(context.Context, *SearchString, *Users) error CreateUser(context.Context, *User, *User) error UpdateUser(context.Context, *User, *User) error DeleteUser(context.Context, *SearchId, *AffectedCount) error @@ -192,12 +215,14 @@ type UserSrvHandler interface { AfterCreateUser(context.Context, *User, *AfterFuncErr) error AfterUpdateUser(context.Context, *User, *AfterFuncErr) error AfterDeleteUser(context.Context, *User, *AfterFuncErr) error + Auth(context.Context, *User, *Token) error } func RegisterUserSrvHandler(s server.Server, hdlr UserSrvHandler, opts ...server.HandlerOption) error { type userSrv interface { GetUserById(ctx context.Context, in *SearchId, out *User) error GetUsers(ctx context.Context, in *SearchParams, out *Users) error + GetUsersByEmail(ctx context.Context, in *SearchString, out *Users) error CreateUser(ctx context.Context, in *User, out *User) error UpdateUser(ctx context.Context, in *User, out *User) error DeleteUser(ctx context.Context, in *SearchId, out *AffectedCount) error @@ -207,6 +232,7 @@ func RegisterUserSrvHandler(s server.Server, hdlr UserSrvHandler, opts ...server AfterCreateUser(ctx context.Context, in *User, out *AfterFuncErr) error AfterUpdateUser(ctx context.Context, in *User, out *AfterFuncErr) error AfterDeleteUser(ctx context.Context, in *User, out *AfterFuncErr) error + Auth(ctx context.Context, in *User, out *Token) error } type UserSrv struct { userSrv @@ -227,6 +253,10 @@ func (h *userSrvHandler) GetUsers(ctx context.Context, in *SearchParams, out *Us return h.UserSrvHandler.GetUsers(ctx, in, out) } +func (h *userSrvHandler) GetUsersByEmail(ctx context.Context, in *SearchString, out *Users) error { + return h.UserSrvHandler.GetUsersByEmail(ctx, in, out) +} + func (h *userSrvHandler) CreateUser(ctx context.Context, in *User, out *User) error { return h.UserSrvHandler.CreateUser(ctx, in, out) } @@ -262,3 +292,7 @@ func (h *userSrvHandler) AfterUpdateUser(ctx context.Context, in *User, out *Aft func (h *userSrvHandler) AfterDeleteUser(ctx context.Context, in *User, out *AfterFuncErr) error { return h.UserSrvHandler.AfterDeleteUser(ctx, in, out) } + +func (h *userSrvHandler) Auth(ctx context.Context, in *User, out *Token) error { + return h.UserSrvHandler.Auth(ctx, in, out) +} diff --git a/user/proto/user.proto b/user/proto/user.proto index a2d3848..ee03e61 100644 --- a/user/proto/user.proto +++ b/user/proto/user.proto @@ -9,6 +9,7 @@ import "google/protobuf/timestamp.proto"; service userSrv { rpc GetUserById(SearchId) returns (user) {} rpc GetUsers(SearchParams) returns (users) {} + rpc GetUsersByEmail(SearchString) returns (users) {} rpc CreateUser(user) returns (user) {} rpc UpdateUser(user) returns (user) {} rpc DeleteUser(SearchId) returns (affectedCount) {} @@ -18,6 +19,7 @@ service userSrv { rpc AfterCreateUser(user) returns (AfterFuncErr) {} rpc AfterUpdateUser(user) returns (AfterFuncErr) {} rpc AfterDeleteUser(user) returns (AfterFuncErr) {} + rpc Auth(user) returns (Token) {} } @@ -43,6 +45,13 @@ message SearchParams { string fisrtname = 2; string lastname = 3; google.protobuf.Timestamp validDate = 5; + string email =9; + string company =10; + string pwd =11; +} + +message SearchString { + string value = 1; } message SearchId { @@ -59,4 +68,9 @@ message validationErr { message AfterFuncErr { repeated string failureDesc = 1; +} + +message Token { + string token = 1; + bool valid = 2; } \ No newline at end of file diff --git a/user/server/handler.go b/user/server/handler.go index 864acc7..551f641 100644 --- a/user/server/handler.go +++ b/user/server/handler.go @@ -40,6 +40,8 @@ func (u *User) GetUserById(ctx context.Context, searchId *pb.SearchId, outUser * &outUser.Active, &outUser.Pwd, &outUser.Name, + &outUser.Email, + &outUser.Company, ) if err != nil { @@ -65,14 +67,11 @@ func (u *User) GetUsers(ctx context.Context, searchParms *pb.SearchParams, users _ = ctx - sqlStatement := statements.SqlSelectAll.String() - sqlWhereClause, values, err2 := u.buildSearchWhereClause(searchParms) + values, sqlStatement, err2 := u.getSQLForSearch(searchParms) if err2 != nil { return err2 } - sqlStatement += sqlWhereClause - //log.Printf("sql: %s\n values: %v", sqlStatement, values) rows, err := conn.Query(context.Background(), sqlStatement, values...) @@ -96,6 +95,8 @@ func (u *User) GetUsers(ctx context.Context, searchParms *pb.SearchParams, users &user.Active, &user.Pwd, &user.Name, + &user.Email, + &user.Company, ) if err != nil { log.Printf(userErr.SelectScanError(err)) @@ -114,6 +115,17 @@ func (u *User) GetUsers(ctx context.Context, searchParms *pb.SearchParams, users return nil } +func (u *User) getSQLForSearch(searchParms *pb.SearchParams) ([]interface{}, string, error) { + sql := statements.SqlSelectAll.String() + sqlWhereClause, values, err := u.buildSearchWhereClause(searchParms) + if err != nil { + return nil, "", err + } + + sqlStatement := fmt.Sprintf(sql, sqlWhereClause, statements.MaxRowsToFetch) + return values, sqlStatement, nil +} + //buildSearchWhereClause: Builds a sql string to be used as the where clause in a sql statement. It also returns an interface //slice with the values to be used as replacements in the sql statement. Currently only handles equality constraints, except //for the date lookup which is done as a contains clause @@ -137,6 +149,16 @@ func (u *User) buildSearchWhereClause(searchParms *pb.SearchParams) (string, []i values = append(values, searchParms.GetLastname()) i++ } + if searchParms.GetEmail() != "" { + sqlWhereClause += fmt.Sprintf(" AND appuser.email = $%d", i) + values = append(values, searchParms.GetEmail()) + i++ + } + if searchParms.GetCompany() != "" { + sqlWhereClause += fmt.Sprintf(" AND appuser.company = $%d", i) + values = append(values, searchParms.GetCompany()) + i++ + } if searchParms.GetValidDate() != nil { convertedDates, err := globalUtils.TimeStampPPBToTime(searchParms.GetValidDate()) if err != nil { @@ -173,6 +195,8 @@ func (u *User) CreateUser(ctx context.Context, inUser *pb.User, outUser *pb.User validThru, inUser.GetActive(), inUser.GetPwd(), + inUser.GetEmail(), + inUser.GetCompany(), ). Scan( &outUser.Id, @@ -183,6 +207,8 @@ func (u *User) CreateUser(ctx context.Context, inUser *pb.User, outUser *pb.User &outUser.Active, &outUser.Pwd, &outUser.Name, + &outUser.Email, + &outUser.Company, ) if errIns != nil { @@ -225,6 +251,8 @@ func (u *User) UpdateUser(ctx context.Context, inUser *pb.User, outUser *pb.User validThru, inUser.GetActive(), inUser.GetPwd(), + inUser.GetEmail(), + inUser.GetCompany(), inUser.GetId(), ).Scan( &outUser.Id, @@ -235,6 +263,8 @@ func (u *User) UpdateUser(ctx context.Context, inUser *pb.User, outUser *pb.User &outUser.Active, &outUser.Pwd, &outUser.Name, + &outUser.Email, + &outUser.Company, ) if err != nil { log.Printf(userErr.UpdateError(err)) @@ -283,3 +313,33 @@ func (u *User) DeleteUser(ctx context.Context, searchid *pb.SearchId, affectedCo return nil } + +func (u *User) Auth(ctx context.Context, user *pb.User, token *pb.Token) error { + _ = ctx + + searchParams := pb.SearchParams{ + Email: user.Email, + Pwd: user.Pwd, + } + outUsers := pb.Users{} + if err := u.GetUsers(ctx, &searchParams, &outUsers); err != nil { + return err + } + + // TODO: Change this + token.Token = "CHANGEME" + token.Valid = false + + return nil +} + +func (u *User) GetUsersByEmail(ctx context.Context, searchString *pb.SearchString, outUsers *pb.Users) error { + searchParams := pb.SearchParams{ + Email: searchString.Value, + } + err := u.GetUsers(ctx, &searchParams, outUsers) + if err != nil { + return err + } + return nil +} diff --git a/user/server/handler_test.go b/user/server/handler_test.go index fa2a654..27e3383 100644 --- a/user/server/handler_test.go +++ b/user/server/handler_test.go @@ -19,13 +19,13 @@ func TestUser_buildSearchWhereClause(t *testing.T) { sqlFullSearch := sqlEmptyWhereClause + " AND appuser.id = $1 AND appuser.firstname = $2 AND appuser.lastname = $3 AND appuser.validfrom <= $4 AND appuser.validthru >= $4" sqlOnlyDateSearch := sqlEmptyWhereClause + " AND appuser.validfrom <= $1 AND appuser.validthru >= $1" sqlOnlyFirstNameSearch := sqlEmptyWhereClause + " AND appuser.firstname = $1" - sqlTestSearch := sqlEmptyWhereClause + " AND appuser.id = $1 AND appuser.firstname = $2 AND appuser.lastname = $3 AND appuser.validfrom <= $4 AND appuser.validthru >= $4" + sqlTestSearch := sqlEmptyWhereClause + " AND appuser.id = $1 AND appuser.firstname = $2 AND appuser.lastname = $3 AND appuser.email = $4 AND appuser.company = $5 AND appuser.validfrom <= $6 AND appuser.validthru >= $6" var intEmptySearch []interface{} intFullSearch := []interface{}{int64(1), "Super", "Duck", convertedDates[0]} intOnlyDateSearch := []interface{}{convertedDates[0]} intOnlyFirstNameSearch := []interface{}{"Super"} - intTestSearch := []interface{}{int64(1234), "Incredible", "Green Guy", convertedDates[0]} + intTestSearch := []interface{}{int64(1234), "Incredible", "Green Guy", "igg@mymail.com", "igg & Associates", convertedDates[0]} emptySearch := pb.SearchParams{} fullSearch := pb.SearchParams{ @@ -43,6 +43,8 @@ func TestUser_buildSearchWhereClause(t *testing.T) { Fisrtname: "Incredible", Lastname: "Green Guy", ValidDate: dtForSearch, + Email: "igg@mymail.com", + Company: "igg & Associates", } tests := []struct { diff --git a/user/server/statements/errorstatements.go b/user/server/statements/errorstatements.go index b2364be..d02b81f 100644 --- a/user/server/statements/errorstatements.go +++ b/user/server/statements/errorstatements.go @@ -17,7 +17,9 @@ type UserErr string var errTxtEn = map[string]UserErr{ "internalError": "Internal error. Error: %v\n", "insertError": "Unable to create user. Error: %v\n", + "insertDupEmail": "Email address already exists in the system\v", "updateError": "Unable to update user. Error: %v \n", + "updateDupEmail": "This email address is already associated with another user in the system\v", "deleteError": "Unable to delete user %v. Error: %v\n", "deleteRowNotFoundError": "row with id %d not found. Unable to delete the row", "selectReadError": "Unable to get rows from the DB. Error: %v \n", @@ -29,7 +31,9 @@ var errTxtEn = map[string]UserErr{ var errTxtES = map[string]UserErr{ "internalError": "Error interno. Error: %v\n", "insertError": "No se pudo crear el usuario. Error: %v\n", + "insertDupEmail": "Correo electornico ya existe en la base de datos\v", "updateError": "No se pudo actualizar el usuario. Error: %v \n", + "updateDupEmail": "Este correo electornico ya esta associado con un usuario en el systema\v", "deleteError": "No se pudo borrar el usuario %v. Error: %v\n", "deleteRowNotFoundError": "usuario %d no se pudo encontrar. No se pudo borrar el usuario", "selectReadError": "No su pudo leer datos de la base de datos. Error: %v \n", @@ -88,3 +92,11 @@ func (ge *UserErr) SelectRowReadError(err error) string { func (ge *UserErr) DelUserActive() string { return fmt.Sprintf(ge.getSqlTxt("delUserActive", language)) } + +func (ge *UserErr) UpdateDupEmail() string { + return fmt.Sprintf(ge.getSqlTxt("updateDupEmail", language)) +} + +func (ge *UserErr) InsertDupEmail() string { + return fmt.Sprintf(ge.getSqlTxt("insertDupEmail", language)) +}