blob: ee385cbe8bfaeacce0bb99268250e1d0cd0177c2 [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 }
iomodo3e1576e2021-02-23 01:27:56 +040021 return s
22}
23
iomodocf795602021-03-07 23:14:15 +040024func (us *userService) GetUser(c context.Context, r *proto.GetUserRequest) (*proto.GetUserResponse, error) {
25 user, err := us.app.GetUser(r.GetId())
26 if err != nil {
27 return nil, errors.Wrap(err, "can't get user from application")
28 }
29 return &proto.GetUserResponse{
30 User: &proto.User{
31 Id: &user.ID,
32 CreateAt: &timestamppb.Timestamp{Seconds: user.CreateAt},
33 UpdateAt: &timestamppb.Timestamp{Seconds: user.UpdateAt},
34 DeleteAt: &timestamppb.Timestamp{Seconds: user.DeleteAt},
35 Username: user.Username,
36 Password: user.Password,
37 LastPasswordUpdate: &timestamppb.Timestamp{Seconds: user.LastPasswordUpdate},
38 },
39 }, nil
iomodo3e1576e2021-02-23 01:27:56 +040040}
41func (us *userService) ListUsers(context.Context, *proto.ListUserRequest) (*proto.ListUserResponse, error) {
42 return nil, nil
43}
iomodocf795602021-03-07 23:14:15 +040044func (us *userService) CreateUser(context.Context, *proto.CreateUserRequest) (*proto.CreateUserResponse, error) {
iomodo3e1576e2021-02-23 01:27:56 +040045 return nil, nil
46}