diff --git a/user/domain/domain.go b/user/domain/domain.go index 3774223..7e0d1a7 100644 --- a/user/domain/domain.go +++ b/user/domain/domain.go @@ -19,6 +19,10 @@ import ( "github.com/sendgrid/sendgrid-go/helpers/mail" ) +var ( + ErrNotFound = errors.New("not found") +) + type pw struct { ID string `json:"id"` Password string `json:"password"` @@ -276,7 +280,7 @@ func (domain *Domain) ReadSession(ctx context.Context, id string) (*user.Session return nil, err } if len(rsp.Records) == 0 { - return nil, errors.New("not found") + return nil, ErrNotFound } m, _ := rsp.Records[0].MarshalJSON() json.Unmarshal(m, sess) @@ -359,7 +363,7 @@ func (domain *Domain) Read(ctx context.Context, userId string) (*user.Account, e return nil, err } if len(rsp.Records) == 0 { - return nil, errors.New("not found") + return nil, ErrNotFound } m, _ := rsp.Records[0].MarshalJSON() json.Unmarshal(m, user) @@ -386,7 +390,7 @@ func (domain *Domain) Search(ctx context.Context, username, email string) ([]*us return nil, err } if len(rsp.Records) == 0 { - return nil, errors.New("not found") + return nil, ErrNotFound } m, _ := rsp.Records[0].MarshalJSON() json.Unmarshal(m, usr) @@ -423,9 +427,39 @@ func (domain *Domain) SaltAndPassword(ctx context.Context, userId string) (strin return "", "", err } if len(rsp.Records) == 0 { - return "", "", errors.New("not found") + return "", "", ErrNotFound } m, _ := rsp.Records[0].MarshalJSON() json.Unmarshal(m, password) return password.Salt, password.Password, nil } + +func (domain *Domain) List(ctx context.Context, o, l int32) ([]*user.Account, error) { + var limit int32 = 25 + var offset int32 = 0 + if l > 0 { + limit = l + } + if o > 0 { + offset = o + } + rsp, err := domain.db.Read(ctx, &db.ReadRequest{ + Table: "users", + Limit: limit, + Offset: offset, + }) + if err != nil { + return nil, err + } + if len(rsp.Records) == 0 { + return nil, ErrNotFound + } + ret := make([]*user.Account, len(rsp.Records)) + for i, v := range rsp.Records { + m, _ := v.MarshalJSON() + var user user.Account + json.Unmarshal(m, &user) + ret[i] = &user + } + return ret, nil +} diff --git a/user/examples.json b/user/examples.json index 6cc947d..6ee09cd 100644 --- a/user/examples.json +++ b/user/examples.json @@ -192,5 +192,39 @@ } } } + ], + "list": [ + { + "title": "List all users", + "run_check": false, + "request": { + "offset": 0, + "limit": 100 + }, + "response": { + "users": [ + { + "id": "user-1", + "username": "joe", + "email": "joe@example.com", + "created": "1637322407", + "updated": "1637322407", + "verified": false, + "verificationDate": "0", + "profile": {} + }, + { + "id": "user-2", + "username": "jane", + "email": "jane@example.com", + "created": "1637324407", + "updated": "1637324407", + "verified": false, + "verificationDate": "0", + "profile": {} + } + ] + } + } ] } diff --git a/user/handler/handler.go b/user/handler/handler.go index 0c00c7a..9a832e8 100644 --- a/user/handler/handler.go +++ b/user/handler/handler.go @@ -1,6 +1,7 @@ package handler import ( + goctx "context" "crypto/rand" "encoding/base64" "fmt" @@ -372,3 +373,15 @@ func (s *User) ResetPassword(ctx context.Context, req *pb.ResetPasswordRequest, return nil } + +func (s *User) List(ctx goctx.Context, request *pb.ListRequest, response *pb.ListResponse) error { + accs, err := s.domain.List(ctx, request.Offset, request.Limit) + if err != nil && err != domain.ErrNotFound { + return errors.InternalServerError("user.List", "Error retrieving user list") + } + response.Users = make([]*pb.Account, len(accs)) + for i, v := range accs { + response.Users[i] = v + } + return nil +} diff --git a/user/proto/user.pb.go b/user/proto/user.pb.go index f3f96c4..7eb751c 100644 --- a/user/proto/user.pb.go +++ b/user/proto/user.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v3.15.6 +// protoc-gen-go v1.26.0 +// protoc v3.15.5 // source: proto/user.proto package user @@ -821,6 +821,7 @@ type ReadSessionResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // the session for the user Session *Session `protobuf:"bytes,1,opt,name=session,proto3" json:"session,omitempty"` } @@ -985,6 +986,7 @@ type LogoutRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // the session id for the user to logout SessionId string `protobuf:"bytes,1,opt,name=sessionId,proto3" json:"sessionId,omitempty"` } @@ -1166,14 +1168,16 @@ type SendVerificationEmailRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` + // email address to send the verification code + Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` + // subject of the email Subject string `protobuf:"bytes,2,opt,name=subject,proto3" json:"subject,omitempty"` // Text content of the email. Don't forget to include the string '$micro_verification_link' which will be replaced by the real verification link // HTML emails are not available currently. TextContent string `protobuf:"bytes,3,opt,name=textContent,proto3" json:"textContent,omitempty"` RedirectUrl string `protobuf:"bytes,4,opt,name=redirectUrl,proto3" json:"redirectUrl,omitempty"` FailureRedirectUrl string `protobuf:"bytes,5,opt,name=failureRedirectUrl,proto3" json:"failureRedirectUrl,omitempty"` - // Display name of the sender for the email. Note: the email address will still be 'support@m3o.com' + // Display name of the sender for the email. Note: the email address will still be 'noreply@email.m3ocontent.com' FromName string `protobuf:"bytes,6,opt,name=fromName,proto3" json:"fromName,omitempty"` } @@ -1303,7 +1307,7 @@ type SendPasswordResetEmailRequest struct { // Text content of the email. Don't forget to include the string '$code' which will be replaced by the real verification link // HTML emails are not available currently. TextContent string `protobuf:"bytes,3,opt,name=textContent,proto3" json:"textContent,omitempty"` - // Display name of the sender for the email. Note: the email address will still be 'support@m3o.com' + // Display name of the sender for the email. Note: the email address will still be 'noreply@email.m3ocontent.com' FromName string `protobuf:"bytes,4,opt,name=fromName,proto3" json:"fromName,omitempty"` } @@ -1519,6 +1523,111 @@ func (*ResetPasswordResponse) Descriptor() ([]byte, []int) { return file_proto_user_proto_rawDescGZIP(), []int{25} } +// List all users +type ListRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Offset int32 `protobuf:"varint,1,opt,name=offset,proto3" json:"offset,omitempty"` + // Maximum number of records to return. Default limit is 25. + // Maximum limit is 1000. Anything higher will return an error. + Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` +} + +func (x *ListRequest) Reset() { + *x = ListRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_user_proto_msgTypes[26] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListRequest) ProtoMessage() {} + +func (x *ListRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_user_proto_msgTypes[26] + 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 ListRequest.ProtoReflect.Descriptor instead. +func (*ListRequest) Descriptor() ([]byte, []int) { + return file_proto_user_proto_rawDescGZIP(), []int{26} +} + +func (x *ListRequest) GetOffset() int32 { + if x != nil { + return x.Offset + } + return 0 +} + +func (x *ListRequest) GetLimit() int32 { + if x != nil { + return x.Limit + } + return 0 +} + +type ListResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Users []*Account `protobuf:"bytes,1,rep,name=users,proto3" json:"users,omitempty"` +} + +func (x *ListResponse) Reset() { + *x = ListResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_user_proto_msgTypes[27] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListResponse) ProtoMessage() {} + +func (x *ListResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_user_proto_msgTypes[27] + 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 ListResponse.ProtoReflect.Descriptor instead. +func (*ListResponse) Descriptor() ([]byte, []int) { + return file_proto_user_proto_rawDescGZIP(), []int{27} +} + +func (x *ListResponse) GetUsers() []*Account { + if x != nil { + return x.Users + } + return nil +} + var File_proto_user_proto protoreflect.FileDescriptor var file_proto_user_proto_rawDesc = []byte{ @@ -1669,60 +1778,70 @@ var file_proto_user_proto_rawDesc = []byte{ 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x17, 0x0a, 0x15, 0x52, 0x65, 0x73, 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xb9, 0x06, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, - 0x35, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, - 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12, 0x11, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x35, - 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, - 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4d, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, - 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1b, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x00, 0x12, 0x32, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x12, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x06, 0x4c, 0x6f, 0x67, 0x6f, - 0x75, 0x74, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x6f, 0x75, 0x74, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, - 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x44, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x18, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, - 0x52, 0x65, 0x61, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, - 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x18, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x56, 0x65, 0x72, 0x69, - 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, - 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x62, 0x0a, 0x15, 0x53, - 0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, - 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x22, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x6e, 0x64, - 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6d, 0x61, 0x69, - 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, - 0x53, 0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x65, 0x0a, 0x16, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, - 0x65, 0x73, 0x65, 0x74, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x23, 0x2e, 0x75, 0x73, 0x65, 0x72, - 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, - 0x65, 0x74, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, - 0x72, 0x64, 0x52, 0x65, 0x73, 0x65, 0x74, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x65, 0x74, 0x50, - 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, - 0x65, 0x73, 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x74, - 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x75, 0x73, - 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3b, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x14, 0x0a, + 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x22, 0x33, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x23, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x32, 0xea, 0x06, 0x0a, 0x04, 0x55, 0x73, 0x65, + 0x72, 0x12, 0x35, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, + 0x12, 0x11, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x06, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x35, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, + 0x72, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4d, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1b, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x32, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, + 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x06, 0x4c, 0x6f, + 0x67, 0x6f, 0x75, 0x74, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x6f, + 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x2e, 0x4c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x44, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x12, 0x18, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x53, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, + 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0b, 0x56, 0x65, 0x72, 0x69, 0x66, + 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x18, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x56, 0x65, + 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, + 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x62, 0x0a, + 0x15, 0x53, 0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x22, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, + 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6d, + 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x75, 0x73, 0x65, + 0x72, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x65, 0x0a, 0x16, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, + 0x64, 0x52, 0x65, 0x73, 0x65, 0x74, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x23, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, + 0x65, 0x73, 0x65, 0x74, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x24, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x61, 0x73, 0x73, + 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x65, 0x74, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x65, + 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1a, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x2e, 0x52, 0x65, 0x73, 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x73, + 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x75, + 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x3b, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1737,7 +1856,7 @@ func file_proto_user_proto_rawDescGZIP() []byte { return file_proto_user_proto_rawDescData } -var file_proto_user_proto_msgTypes = make([]protoimpl.MessageInfo, 29) +var file_proto_user_proto_msgTypes = make([]protoimpl.MessageInfo, 31) var file_proto_user_proto_goTypes = []interface{}{ (*Account)(nil), // 0: user.Account (*Session)(nil), // 1: user.Session @@ -1765,47 +1884,52 @@ var file_proto_user_proto_goTypes = []interface{}{ (*SendPasswordResetEmailResponse)(nil), // 23: user.SendPasswordResetEmailResponse (*ResetPasswordRequest)(nil), // 24: user.ResetPasswordRequest (*ResetPasswordResponse)(nil), // 25: user.ResetPasswordResponse - nil, // 26: user.Account.ProfileEntry - nil, // 27: user.CreateRequest.ProfileEntry - nil, // 28: user.UpdateRequest.ProfileEntry + (*ListRequest)(nil), // 26: user.ListRequest + (*ListResponse)(nil), // 27: user.ListResponse + nil, // 28: user.Account.ProfileEntry + nil, // 29: user.CreateRequest.ProfileEntry + nil, // 30: user.UpdateRequest.ProfileEntry } var file_proto_user_proto_depIdxs = []int32{ - 26, // 0: user.Account.profile:type_name -> user.Account.ProfileEntry - 27, // 1: user.CreateRequest.profile:type_name -> user.CreateRequest.ProfileEntry + 28, // 0: user.Account.profile:type_name -> user.Account.ProfileEntry + 29, // 1: user.CreateRequest.profile:type_name -> user.CreateRequest.ProfileEntry 0, // 2: user.CreateResponse.account:type_name -> user.Account 0, // 3: user.ReadResponse.account:type_name -> user.Account - 28, // 4: user.UpdateRequest.profile:type_name -> user.UpdateRequest.ProfileEntry + 30, // 4: user.UpdateRequest.profile:type_name -> user.UpdateRequest.ProfileEntry 1, // 5: user.ReadSessionResponse.session:type_name -> user.Session 1, // 6: user.LoginResponse.session:type_name -> user.Session - 2, // 7: user.User.Create:input_type -> user.CreateRequest - 6, // 8: user.User.Read:input_type -> user.ReadRequest - 8, // 9: user.User.Update:input_type -> user.UpdateRequest - 4, // 10: user.User.Delete:input_type -> user.DeleteRequest - 10, // 11: user.User.UpdatePassword:input_type -> user.UpdatePasswordRequest - 14, // 12: user.User.Login:input_type -> user.LoginRequest - 16, // 13: user.User.Logout:input_type -> user.LogoutRequest - 12, // 14: user.User.ReadSession:input_type -> user.ReadSessionRequest - 18, // 15: user.User.VerifyEmail:input_type -> user.VerifyEmailRequest - 20, // 16: user.User.SendVerificationEmail:input_type -> user.SendVerificationEmailRequest - 22, // 17: user.User.SendPasswordResetEmail:input_type -> user.SendPasswordResetEmailRequest - 24, // 18: user.User.ResetPassword:input_type -> user.ResetPasswordRequest - 3, // 19: user.User.Create:output_type -> user.CreateResponse - 7, // 20: user.User.Read:output_type -> user.ReadResponse - 9, // 21: user.User.Update:output_type -> user.UpdateResponse - 5, // 22: user.User.Delete:output_type -> user.DeleteResponse - 11, // 23: user.User.UpdatePassword:output_type -> user.UpdatePasswordResponse - 15, // 24: user.User.Login:output_type -> user.LoginResponse - 17, // 25: user.User.Logout:output_type -> user.LogoutResponse - 13, // 26: user.User.ReadSession:output_type -> user.ReadSessionResponse - 19, // 27: user.User.VerifyEmail:output_type -> user.VerifyEmailResponse - 21, // 28: user.User.SendVerificationEmail:output_type -> user.SendVerificationEmailResponse - 23, // 29: user.User.SendPasswordResetEmail:output_type -> user.SendPasswordResetEmailResponse - 25, // 30: user.User.ResetPassword:output_type -> user.ResetPasswordResponse - 19, // [19:31] is the sub-list for method output_type - 7, // [7:19] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 0, // 7: user.ListResponse.users:type_name -> user.Account + 2, // 8: user.User.Create:input_type -> user.CreateRequest + 6, // 9: user.User.Read:input_type -> user.ReadRequest + 8, // 10: user.User.Update:input_type -> user.UpdateRequest + 4, // 11: user.User.Delete:input_type -> user.DeleteRequest + 10, // 12: user.User.UpdatePassword:input_type -> user.UpdatePasswordRequest + 14, // 13: user.User.Login:input_type -> user.LoginRequest + 16, // 14: user.User.Logout:input_type -> user.LogoutRequest + 12, // 15: user.User.ReadSession:input_type -> user.ReadSessionRequest + 18, // 16: user.User.VerifyEmail:input_type -> user.VerifyEmailRequest + 20, // 17: user.User.SendVerificationEmail:input_type -> user.SendVerificationEmailRequest + 22, // 18: user.User.SendPasswordResetEmail:input_type -> user.SendPasswordResetEmailRequest + 24, // 19: user.User.ResetPassword:input_type -> user.ResetPasswordRequest + 26, // 20: user.User.List:input_type -> user.ListRequest + 3, // 21: user.User.Create:output_type -> user.CreateResponse + 7, // 22: user.User.Read:output_type -> user.ReadResponse + 9, // 23: user.User.Update:output_type -> user.UpdateResponse + 5, // 24: user.User.Delete:output_type -> user.DeleteResponse + 11, // 25: user.User.UpdatePassword:output_type -> user.UpdatePasswordResponse + 15, // 26: user.User.Login:output_type -> user.LoginResponse + 17, // 27: user.User.Logout:output_type -> user.LogoutResponse + 13, // 28: user.User.ReadSession:output_type -> user.ReadSessionResponse + 19, // 29: user.User.VerifyEmail:output_type -> user.VerifyEmailResponse + 21, // 30: user.User.SendVerificationEmail:output_type -> user.SendVerificationEmailResponse + 23, // 31: user.User.SendPasswordResetEmail:output_type -> user.SendPasswordResetEmailResponse + 25, // 32: user.User.ResetPassword:output_type -> user.ResetPasswordResponse + 27, // 33: user.User.List:output_type -> user.ListResponse + 21, // [21:34] is the sub-list for method output_type + 8, // [8:21] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_proto_user_proto_init() } @@ -2126,6 +2250,30 @@ func file_proto_user_proto_init() { return nil } } + file_proto_user_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_user_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListResponse); 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{ @@ -2133,7 +2281,7 @@ func file_proto_user_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_user_proto_rawDesc, NumEnums: 0, - NumMessages: 29, + NumMessages: 31, NumExtensions: 0, NumServices: 1, }, diff --git a/user/proto/user.pb.micro.go b/user/proto/user.pb.micro.go index c375448..ea59448 100644 --- a/user/proto/user.pb.micro.go +++ b/user/proto/user.pb.micro.go @@ -54,6 +54,7 @@ type UserService interface { SendVerificationEmail(ctx context.Context, in *SendVerificationEmailRequest, opts ...client.CallOption) (*SendVerificationEmailResponse, error) SendPasswordResetEmail(ctx context.Context, in *SendPasswordResetEmailRequest, opts ...client.CallOption) (*SendPasswordResetEmailResponse, error) ResetPassword(ctx context.Context, in *ResetPasswordRequest, opts ...client.CallOption) (*ResetPasswordResponse, error) + List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) } type userService struct { @@ -188,6 +189,16 @@ func (c *userService) ResetPassword(ctx context.Context, in *ResetPasswordReques return out, nil } +func (c *userService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "User.List", in) + out := new(ListResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for User service type UserHandler interface { @@ -203,6 +214,7 @@ type UserHandler interface { SendVerificationEmail(context.Context, *SendVerificationEmailRequest, *SendVerificationEmailResponse) error SendPasswordResetEmail(context.Context, *SendPasswordResetEmailRequest, *SendPasswordResetEmailResponse) error ResetPassword(context.Context, *ResetPasswordRequest, *ResetPasswordResponse) error + List(context.Context, *ListRequest, *ListResponse) error } func RegisterUserHandler(s server.Server, hdlr UserHandler, opts ...server.HandlerOption) error { @@ -219,6 +231,7 @@ func RegisterUserHandler(s server.Server, hdlr UserHandler, opts ...server.Handl SendVerificationEmail(ctx context.Context, in *SendVerificationEmailRequest, out *SendVerificationEmailResponse) error SendPasswordResetEmail(ctx context.Context, in *SendPasswordResetEmailRequest, out *SendPasswordResetEmailResponse) error ResetPassword(ctx context.Context, in *ResetPasswordRequest, out *ResetPasswordResponse) error + List(ctx context.Context, in *ListRequest, out *ListResponse) error } type User struct { user @@ -278,3 +291,7 @@ func (h *userHandler) SendPasswordResetEmail(ctx context.Context, in *SendPasswo func (h *userHandler) ResetPassword(ctx context.Context, in *ResetPasswordRequest, out *ResetPasswordResponse) error { return h.UserHandler.ResetPassword(ctx, in, out) } + +func (h *userHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.UserHandler.List(ctx, in, out) +} diff --git a/user/proto/user.proto b/user/proto/user.proto index e07b927..ef139c2 100644 --- a/user/proto/user.proto +++ b/user/proto/user.proto @@ -17,6 +17,7 @@ service User { rpc SendVerificationEmail(SendVerificationEmailRequest) returns (SendVerificationEmailResponse) {} rpc SendPasswordResetEmail(SendPasswordResetEmailRequest) returns (SendPasswordResetEmailResponse) {} rpc ResetPassword(ResetPasswordRequest) returns (ResetPasswordResponse) {} + rpc List(ListRequest) returns(ListResponse) {} } message Account { @@ -224,3 +225,15 @@ message ResetPasswordRequest { } message ResetPasswordResponse {} + +// List all users. Returns a paged list of results +message ListRequest { + int32 offset = 1; + // Maximum number of records to return. Default limit is 25. + // Maximum limit is 1000. Anything higher will return an error. + int32 limit = 2; +} + +message ListResponse { + repeated Account users = 1; +}