(ctx context.Context, req *schema.QuestionRecoverReq)
| 730 | } |
| 731 | |
| 732 | func (qs *QuestionService) RecoverQuestion(ctx context.Context, req *schema.QuestionRecoverReq) (err error) { |
| 733 | questionInfo, exist, err := qs.questionRepo.GetQuestion(ctx, req.QuestionID) |
| 734 | if err != nil { |
| 735 | return err |
| 736 | } |
| 737 | if !exist { |
| 738 | return errors.BadRequest(reason.QuestionNotFound) |
| 739 | } |
| 740 | if questionInfo.Status != entity.QuestionStatusDeleted { |
| 741 | return nil |
| 742 | } |
| 743 | |
| 744 | err = qs.questionRepo.RecoverQuestion(ctx, req.QuestionID) |
| 745 | if err != nil { |
| 746 | return err |
| 747 | } |
| 748 | |
| 749 | // update user's question count |
| 750 | userQuestionCount, err := qs.questioncommon.GetUserQuestionCount(ctx, questionInfo.UserID) |
| 751 | if err != nil { |
| 752 | log.Error("user GetUserQuestionCount error", err.Error()) |
| 753 | } else { |
| 754 | err = qs.userCommon.UpdateQuestionCount(ctx, questionInfo.UserID, userQuestionCount) |
| 755 | if err != nil { |
| 756 | log.Error("user IncreaseQuestionCount error", err.Error()) |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | // update tag's question count |
| 761 | if err = qs.tagCommon.RecoverTagRelListByObjectID(ctx, questionInfo.ID); err != nil { |
| 762 | log.Errorf("remove tag rel list by object id error %v", err) |
| 763 | } |
| 764 | |
| 765 | tagIDs := make([]string, 0) |
| 766 | tags, err := qs.tagCommon.GetObjectEntityTag(ctx, questionInfo.ID) |
| 767 | if err != nil { |
| 768 | return err |
| 769 | } |
| 770 | for _, v := range tags { |
| 771 | tagIDs = append(tagIDs, v.ID) |
| 772 | } |
| 773 | if len(tagIDs) > 0 { |
| 774 | if err = qs.tagCommon.RefreshTagQuestionCount(ctx, tagIDs); err != nil { |
| 775 | log.Errorf("update tag's question count failed, %v", err) |
| 776 | } |
| 777 | } |
| 778 | err = qs.questionRepo.RecoverQuestionLink(ctx, &entity.QuestionLink{ |
| 779 | FromQuestionID: questionInfo.ID, |
| 780 | }, &entity.QuestionLink{ |
| 781 | ToQuestionID: questionInfo.ID, |
| 782 | }) |
| 783 | if err != nil { |
| 784 | return |
| 785 | } |
| 786 | |
| 787 | qs.activityQueueService.Send(ctx, &schema.ActivityMsg{ |
| 788 | UserID: req.UserID, |
| 789 | TriggerUserID: converter.StringToInt64(req.UserID), |
nothing calls this directly
no test coverage detected