/
user.go
57 lines (50 loc) · 1.35 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package interfaces
import (
"context"
"github.com/f-rambo/ocean/api/user/v1alpha1"
"github.com/f-rambo/ocean/internal/biz"
"github.com/f-rambo/ocean/internal/conf"
"google.golang.org/protobuf/types/known/emptypb"
)
type UserInterface struct {
v1alpha1.UnimplementedUserInterfaceServer
uc *biz.UserUseCase
authConf *conf.Auth
}
func NewUserInterface(uc *biz.UserUseCase, conf *conf.Bootstrap) *UserInterface {
cAuth := conf.GetOceanAuth()
return &UserInterface{uc: uc, authConf: &cAuth}
}
func (u *UserInterface) SignIn(ctx context.Context, in *v1alpha1.SignIn) (*v1alpha1.User, error) {
token, err := u.uc.SignIn(ctx, in.Email, in.Password)
if err != nil {
return nil, err
}
user, err := u.uc.CheckJWT(ctx, token)
if err != nil {
return nil, err
}
return &v1alpha1.User{
Id: user.ID,
Email: user.Email,
Username: user.Name,
Token: token,
ExpHour: u.authConf.Exp,
}, nil
}
func (u *UserInterface) SignOut(ctx context.Context, in *emptypb.Empty) (*v1alpha1.Msg, error) {
return nil, nil
}
func (u *UserInterface) GetUserInfo(ctx context.Context, in *emptypb.Empty) (*v1alpha1.User, error) {
user, err := u.uc.GetUserInfo(ctx)
if err != nil {
return nil, err
}
return &v1alpha1.User{
Id: user.ID,
Email: user.Email,
Username: user.Name,
Token: user.PassWord,
ExpHour: u.authConf.Exp,
}, nil
}