| iomodo | 3e1576e | 2021-02-23 01:27:56 +0400 | [diff] [blame] | 1 | package rpc |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| iomodo | 3e1576e | 2021-02-23 01:27:56 +0400 | [diff] [blame] | 6 | "github.com/giolekva/pcloud/core/kg/model/proto" |
| iomodo | cf79560 | 2021-03-07 23:14:15 +0400 | [diff] [blame^] | 7 | "github.com/pkg/errors" |
| 8 | "google.golang.org/protobuf/types/known/timestamppb" |
| iomodo | 3e1576e | 2021-02-23 01:27:56 +0400 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | type userService struct { |
| 12 | proto.UnimplementedUserServiceServer |
| iomodo | cf79560 | 2021-03-07 23:14:15 +0400 | [diff] [blame^] | 13 | app appIface |
| iomodo | 3e1576e | 2021-02-23 01:27:56 +0400 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | // NewService returns new user service |
| iomodo | cf79560 | 2021-03-07 23:14:15 +0400 | [diff] [blame^] | 17 | func NewService(app appIface) proto.UserServiceServer { |
| iomodo | 3e1576e | 2021-02-23 01:27:56 +0400 | [diff] [blame] | 18 | s := &userService{ |
| 19 | app: app, |
| 20 | } |
| 21 | |
| 22 | return s |
| 23 | } |
| 24 | |
| iomodo | cf79560 | 2021-03-07 23:14:15 +0400 | [diff] [blame^] | 25 | func (us *userService) GetUser(c context.Context, r *proto.GetUserRequest) (*proto.GetUserResponse, error) { |
| 26 | user, err := us.app.GetUser(r.GetId()) |
| 27 | if err != nil { |
| 28 | return nil, errors.Wrap(err, "can't get user from application") |
| 29 | } |
| 30 | return &proto.GetUserResponse{ |
| 31 | User: &proto.User{ |
| 32 | Id: &user.ID, |
| 33 | CreateAt: ×tamppb.Timestamp{Seconds: user.CreateAt}, |
| 34 | UpdateAt: ×tamppb.Timestamp{Seconds: user.UpdateAt}, |
| 35 | DeleteAt: ×tamppb.Timestamp{Seconds: user.DeleteAt}, |
| 36 | Username: user.Username, |
| 37 | Password: user.Password, |
| 38 | LastPasswordUpdate: ×tamppb.Timestamp{Seconds: user.LastPasswordUpdate}, |
| 39 | }, |
| 40 | }, nil |
| iomodo | 3e1576e | 2021-02-23 01:27:56 +0400 | [diff] [blame] | 41 | } |
| 42 | func (us *userService) ListUsers(context.Context, *proto.ListUserRequest) (*proto.ListUserResponse, error) { |
| 43 | return nil, nil |
| 44 | } |
| iomodo | cf79560 | 2021-03-07 23:14:15 +0400 | [diff] [blame^] | 45 | func (us *userService) CreateUser(context.Context, *proto.CreateUserRequest) (*proto.CreateUserResponse, error) { |
| iomodo | 3e1576e | 2021-02-23 01:27:56 +0400 | [diff] [blame] | 46 | return nil, nil |
| 47 | } |