UpdateQuestion update question
(ctx context.Context, req *schema.QuestionUpdate)
| 904 | |
| 905 | // UpdateQuestion update question |
| 906 | func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.QuestionUpdate) (questionInfo any, err error) { |
| 907 | var canUpdate bool |
| 908 | questionInfo = &schema.QuestionInfoResp{} |
| 909 | |
| 910 | _, existUnreviewed, err := qs.revisionService.ExistUnreviewedByObjectID(ctx, req.ID) |
| 911 | if err != nil { |
| 912 | return |
| 913 | } |
| 914 | if existUnreviewed { |
| 915 | err = errors.BadRequest(reason.QuestionCannotUpdate) |
| 916 | return |
| 917 | } |
| 918 | |
| 919 | dbinfo, has, err := qs.questionRepo.GetQuestion(ctx, req.ID) |
| 920 | if err != nil { |
| 921 | return |
| 922 | } |
| 923 | if !has { |
| 924 | return |
| 925 | } |
| 926 | if dbinfo.Status == entity.QuestionStatusDeleted { |
| 927 | err = errors.BadRequest(reason.QuestionCannotUpdate) |
| 928 | return nil, err |
| 929 | } |
| 930 | |
| 931 | now := time.Now() |
| 932 | question := &entity.Question{} |
| 933 | question.Title = req.Title |
| 934 | question.OriginalText = req.Content |
| 935 | question.ParsedText = req.HTML |
| 936 | question.ID = uid.DeShortID(req.ID) |
| 937 | question.UpdatedAt = now |
| 938 | question.PostUpdateTime = now |
| 939 | question.UserID = dbinfo.UserID |
| 940 | question.LastEditUserID = req.UserID |
| 941 | |
| 942 | minimumContentLength, err := qs.questioncommon.GetMinimumContentLength(ctx) |
| 943 | if err != nil { |
| 944 | return |
| 945 | } |
| 946 | if len(req.Content) < minimumContentLength { |
| 947 | errorlist := make([]*validator.FormErrorField, 0) |
| 948 | errorlist = append(errorlist, &validator.FormErrorField{ |
| 949 | ErrorField: "content", |
| 950 | ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionContentLessThanMinimum), |
| 951 | }) |
| 952 | err = errors.BadRequest(reason.QuestionContentLessThanMinimum) |
| 953 | return errorlist, err |
| 954 | } |
| 955 | |
| 956 | oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID) |
| 957 | if tagerr != nil { |
| 958 | return questionInfo, tagerr |
| 959 | } |
| 960 | |
| 961 | tagNameList := make([]string, 0) |
| 962 | oldtagNameList := make([]string, 0) |
| 963 | for _, tag := range req.Tags { |
nothing calls this directly
no test coverage detected