Refactor code

pull/131/head
wenxu12345 3 years ago
parent 5ae6e98572
commit 6d9ee74360

@ -453,7 +453,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
log.NewInfo(req.OperationID, "JoinGroup args ", req.String()) log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
_, err := imdb.GetUserByUserID(req.OpUserID) _, err := imdb.GetUserByUserID(req.OpUserID)
if err != nil { if err != nil {
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OpUserID) log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} }

@ -23,11 +23,10 @@ func UpdateGroupRequest(groupRequest GroupRequest) error {
if err != nil { if err != nil {
return err return err
} }
err = dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).Error //RowsAffected
if err != nil { if dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).RowsAffected == 0 {
return err return InsertIntoGroupRequest(groupRequest)
} }
return nil
} }
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error { func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {

Loading…
Cancel
Save