blob: c0ddd2190f4c0a807c72d893ecf81c3b67c1e5a0 [file] [log] [blame]
iomodo3e1576e2021-02-23 01:27:56 +04001package rpc
2
3import (
4 "context"
5
iomodo3e1576e2021-02-23 01:27:56 +04006 "github.com/giolekva/pcloud/core/kg/model/proto"
iomodocf795602021-03-07 23:14:15 +04007 "github.com/pkg/errors"
8 "google.golang.org/protobuf/types/known/timestamppb"
iomodo3e1576e2021-02-23 01:27:56 +04009)
10
11type userService struct {
12 proto.UnimplementedUserServiceServer
iomodocf795602021-03-07 23:14:15 +040013 app appIface
iomodo3e1576e2021-02-23 01:27:56 +040014}
15
16// NewService returns new user service
iomodocf795602021-03-07 23:14:15 +040017func NewService(app appIface) proto.UserServiceServer {
iomodo3e1576e2021-02-23 01:27:56 +040018 s := &userService{
19 app: app,
20 }
21
22 return s
23}
24
iomodocf795602021-03-07 23:14:15 +040025func (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: &timestamppb.Timestamp{Seconds: user.CreateAt},
34 UpdateAt: &timestamppb.Timestamp{Seconds: user.UpdateAt},
35 DeleteAt: &timestamppb.Timestamp{Seconds: user.DeleteAt},
36 Username: user.Username,
37 Password: user.Password,
38 LastPasswordUpdate: &timestamppb.Timestamp{Seconds: user.LastPasswordUpdate},
39 },
40 }, nil
iomodo3e1576e2021-02-23 01:27:56 +040041}
42func (us *userService) ListUsers(context.Context, *proto.ListUserRequest) (*proto.ListUserResponse, error) {
43 return nil, nil
44}
iomodocf795602021-03-07 23:14:15 +040045func (us *userService) CreateUser(context.Context, *proto.CreateUserRequest) (*proto.CreateUserResponse, error) {
iomodo3e1576e2021-02-23 01:27:56 +040046 return nil, nil
47}