fix: some api bug
This commit is contained in:
@@ -6,15 +6,15 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/converter"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/users/api/internal/svc"
|
||||
"juwan-backend/app/users/api/internal/types"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
)
|
||||
|
||||
type GetMeLogic struct {
|
||||
@@ -35,19 +35,34 @@ func NewGetMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMeLogic
|
||||
func (l *GetMeLogic) GetMe() (resp *types.User, err error) {
|
||||
userId, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New("illegal id")
|
||||
logx.Errorf("get user id from context: %v", err)
|
||||
return nil, errors.New("illegal user")
|
||||
}
|
||||
|
||||
user, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
||||
Id: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New("get user by id error")
|
||||
logx.Errorf("GetMeLogic.GetUsersById err: %v", err)
|
||||
return nil, errors.New("get user failed")
|
||||
}
|
||||
err = converter.StructToStruct(user, &resp)
|
||||
createAt := time.Unix(user.Users.CreatedAt, 0)
|
||||
resp.CreatedAt = createAt.Format(time.DateTime)
|
||||
logx.Debugf("get user resp: %+v", user)
|
||||
|
||||
resp = &types.User{}
|
||||
|
||||
err = copier.Copy(&resp, user.Users)
|
||||
if err != nil {
|
||||
return nil, errors.New("to struct error")
|
||||
logx.Errorf("copier.Copy err: %v", err)
|
||||
return nil, errors.New("copy user failed")
|
||||
}
|
||||
|
||||
var verificationStatus map[string]string
|
||||
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
|
||||
if err != nil {
|
||||
logx.Errorf("json.Unmarshal err: %v", err)
|
||||
}
|
||||
resp.VerifiedRoles = user.Users.VerifiedRoles
|
||||
resp.VerificationStatus = verificationStatus
|
||||
resp.CreatedAt = time.Unix(user.Users.CreatedAt, 0).Format(time.DateTime)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user