tidy code

This commit is contained in:
wenxu12345 2021-12-28 18:18:35 +08:00
parent 141936e609
commit 6d589a1204
4 changed files with 20 additions and 11 deletions

View File

@ -81,6 +81,6 @@ func UserToken(c *gin.Context) {
resp := api.UserTokenResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg},
UserToken: api.UserTokenInfo{UserID: req.FromUserID, Token: reply.Token, ExpiredTime: reply.ExpiredTime}}
c.JSON(http.StatusOK, resp)
log.NewInfo(req.OperationID, "UserRegister return ", resp)
c.JSON(http.StatusOK, resp)
}

View File

@ -79,11 +79,12 @@ import (
func GetUserInfo(c *gin.Context) {
params := api.GetUserInfoReq{}
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
return
}
req := &rpc.GetUserInfoReq{}
utils.CopyStructFields(&req, params)
utils.CopyStructFields(req, &params)
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
@ -102,21 +103,20 @@ func GetUserInfo(c *gin.Context) {
return
}
resp := api.GetUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
resp.UserInfoList = RpcResp.UserInfoList
c.JSON(http.StatusOK, resp)
resp := api.GetUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: RpcResp.UserInfoList}
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
c.JSON(http.StatusOK, resp)
}
func UpdateUserInfo(c *gin.Context) {
params := api.GetUserInfoReq{}
params := api.UpdateUserInfoReq{}
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &rpc.UpdateUserInfoReq{}
utils.CopyStructFields(&req, params)
utils.CopyStructFields(req, &params)
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
@ -134,6 +134,7 @@ func UpdateUserInfo(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.CommonResp.ErrCode, "errMsg": RpcResp.CommonResp.ErrMsg})
log.NewInfo(req.OperationID, "UpdateUserInfo api return ", RpcResp.CommonResp)
resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp)
c.JSON(http.StatusOK, resp)
}

View File

@ -434,7 +434,6 @@ func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.Get
var userInfo sdkws.FriendRequest
utils.CopyStructFields(&userInfo, applyUserInfo)
appleUserList = append(appleUserList, &userInfo)
}
log.NewInfo(req.CommID.OperationID, "rpc GetFriendApplyList ok", pbFriend.GetFriendApplyListResp{FriendRequestList: appleUserList})
return &pbFriend.GetFriendApplyListResp{FriendRequestList: appleUserList}, nil

View File

@ -26,3 +26,12 @@ type GetUserInfoResp struct {
CommResp
UserInfoList []*open_im_sdk.UserInfo `json:"data"`
}
type UpdateUserInfoReq struct {
UserInfo
OperationID string `json:"operationID" binding:"required"`
}
type UpdateUserInfoResp struct {
CommResp
}