63 lines
1.4 KiB
Go
Raw Permalink Normal View History

package user
import (
"context"
"muyu-apiserver/gateway/internal/svc"
"muyu-apiserver/gateway/internal/types"
"muyu-apiserver/rpc/system/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListUserLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserLogic {
return &ListUserLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListUserLogic) ListUser(req *types.ListUserReq) (resp *types.ListUserResp, err error) {
rpcResp, err := l.svcCtx.SystemRpc.ListUser(l.ctx, &pb.ListUserReq{
Page: req.Page,
PageSize: req.PageSize,
Username: req.Username,
RealName: req.RealName,
Phone: req.Phone,
Status: req.Status,
})
if err != nil {
return nil, err
}
list := make([]types.UserInfo, 0, len(rpcResp.List))
for _, u := range rpcResp.List {
list = append(list, types.UserInfo{
UserId: u.UserId,
Username: u.Username,
RealName: u.RealName,
Phone: u.Phone,
Email: u.Email,
Avatar: u.Avatar,
Status: u.Status,
RoleId: u.RoleId,
RoleName: u.RoleName,
LastLoginTime: u.LastLoginTime,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
})
}
return &types.ListUserResp{
Total: rpcResp.Total,
List: list,
}, nil
}