Refactor code

pull/131/head
wenxu12345 3 years ago
parent 8b1a7def38
commit 492915567b

@ -489,7 +489,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
groupRequest.ReqMsg = req.ReqMessage groupRequest.ReqMsg = req.ReqMessage
groupRequest.GroupID = req.GroupID groupRequest.GroupID = req.GroupID
err = imdb.UpdateGroupRequest(groupRequest) err = imdb.InsertIntoGroupRequest(groupRequest)
if err != nil { if err != nil {
log.NewError(req.OperationID, "UpdateGroupRequest ", err.Error(), groupRequest) log.NewError(req.OperationID, "UpdateGroupRequest ", err.Error(), groupRequest)
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

@ -27,13 +27,7 @@ func UpdateGroupRequest(groupRequest GroupRequest) error {
if groupRequest.HandledTime.Unix() < 0 { if groupRequest.HandledTime.Unix() < 0 {
groupRequest.HandledTime = utils.UnixSecondToTime(0) groupRequest.HandledTime = utils.UnixSecondToTime(0)
} }
t := dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest) return dbConn.Table("group_request").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).Error
//RowsAffected
if t.RowsAffected == 0 {
return InsertIntoGroupRequest(groupRequest)
} else {
return t.Error
}
} }
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error { func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {

Loading…
Cancel
Save