app-cloudep-member-server/internal/logic/account/get_user_info_logic.go

67 lines
1.6 KiB
Go

package accountlogic
import (
"app-cloudep-member-server/gen_result/pb/member"
"app-cloudep-member-server/internal/model"
"app-cloudep-member-server/internal/svc"
ers "code.30cm.net/digimon/library-go/errors"
"context"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/protobuf/proto"
)
type GetUserInfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
return &GetUserInfoLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetUserInfo 取得會員資訊
func (l *GetUserInfoLogic) GetUserInfo(in *member.GetUserInfoReq) (*member.GetUserInfoResp, error) {
var entity *model.UserTable
var err error
if in.GetUid() != "" {
entity, err = l.svcCtx.UserModel.FindOneByUid(l.ctx, in.GetUid())
if err != nil {
return nil, ers.DBError(err.Error())
}
} else {
if in.GetNickName() != "" {
entity, err = l.svcCtx.UserModel.FindOneByNickName(l.ctx, in.GetNickName())
if err != nil {
return nil, ers.DBError(err.Error())
}
}
}
if entity != nil {
return &member.GetUserInfoResp{
Data: &member.UserInfo{
Uid: entity.Uid,
AlarmType: member.AlarmType(entity.AlarmType),
VerifyType: member.VerifyType(entity.VerifyType),
Status: member.MemberStatus(entity.Status),
NickName: proto.String(entity.NickName),
Language: entity.Language,
Currency: entity.Currency,
Avatar: entity.Avatar,
CreateTime: entity.CreateTime,
UpdateTime: entity.UpdateTime,
},
}, nil
}
return nil, ers.ResourceNotFound("filed to get user info")
}