Refactor code

pull/131/head
wenxu12345 3 years ago
parent ef67aa9e48
commit 8cd38693dd

@ -68,17 +68,19 @@ func ImportFriend(c *gin.Context) {
client := rpc.NewFriendClient(etcdConn) client := rpc.NewFriendClient(etcdConn)
RpcResp, err := client.ImportFriend(context.Background(), req) RpcResp, err := client.ImportFriend(context.Background(), req)
if err != nil { if err != nil {
log.NewError(req.OperationID, "ImportFriend failed", err.Error(), req.String()) log.NewError(req.OperationID, "ImportFriend failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed " + err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed "})
return return
} }
resp := api.ImportFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} resp := api.ImportFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
if resp.ErrCode == 0 { if resp.ErrCode == 0 {
for _, v := range RpcResp.UserIDResultList { for _, v := range RpcResp.UserIDResultList {
resp.UserIDResultList = append(resp.UserIDResultList, api.UserIDResult{v.UserID, v.Result}) resp.UserIDResultList = append(resp.UserIDResultList, api.UserIDResult{UserID: v.UserID, Result: v.Result})
} }
} }
if len(resp.UserIDResultList) == 0 {
resp.UserIDResultList = []api.UserIDResult{}
}
log.NewInfo(req.OperationID, "ImportFriend api return ", resp) log.NewInfo(req.OperationID, "ImportFriend api return ", resp)
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
} }

@ -21,8 +21,8 @@ type ImportFriendReq struct {
FromUserID string `json:"fromUserID" binding:"required"` FromUserID string `json:"fromUserID" binding:"required"`
} }
type UserIDResult struct { type UserIDResult struct {
UserID string `json:"userID" binding:"required"` UserID string `json:"userID""`
Result int32 `json:"result" binding:"required"` Result int32 `json:"result"`
} }
type ImportFriendResp struct { type ImportFriendResp struct {
CommResp CommResp

Loading…
Cancel
Save