-
-
Notifications
You must be signed in to change notification settings - Fork 264
/
get_user_by_username_logic.go
54 lines (45 loc) · 1.63 KB
/
get_user_by_username_logic.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
package user
import (
"context"
"github.com/suyuan32/simple-admin-common/utils/pointy"
"github.com/suyuan32/simple-admin-core/rpc/ent/user"
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
"github.com/suyuan32/simple-admin-core/rpc/internal/utils/dberrorhandler"
"github.com/suyuan32/simple-admin-core/rpc/types/core"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserByUsernameLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserByUsernameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserByUsernameLogic {
return &GetUserByUsernameLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetUserByUsernameLogic) GetUserByUsername(in *core.UsernameReq) (*core.UserInfo, error) {
result, err := l.svcCtx.DB.User.Query().Where(user.UsernameEQ(in.Username)).WithRoles().First(l.ctx)
if err != nil {
return nil, dberrorhandler.DefaultEntError(l.Logger, err, in)
}
return &core.UserInfo{
Nickname: &result.Nickname,
Avatar: &result.Avatar,
Password: &result.Password,
RoleIds: GetRoleIds(result.Edges.Roles),
RoleCodes: GetRoleCodes(result.Edges.Roles),
Mobile: &result.Mobile,
Email: &result.Email,
Status: pointy.GetPointer(uint32(result.Status)),
Id: pointy.GetPointer(result.ID.String()),
Username: &result.Username,
HomePath: &result.HomePath,
Description: &result.Description,
DepartmentId: &result.DepartmentID,
CreatedAt: pointy.GetPointer(result.CreatedAt.UnixMilli()),
UpdatedAt: pointy.GetPointer(result.UpdatedAt.UnixMilli()),
}, nil
}