MCPcopy Index your code
hub / github.com/apache/answer / UpdateQuestion

Method UpdateQuestion

internal/service/content/question_service.go:906–1085  ·  view source on GitHub ↗

UpdateQuestion update question

(ctx context.Context, req *schema.QuestionUpdate)

Source from the content-addressed store, hash-verified

904
905// UpdateQuestion update question
906func (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 {

Callers

nothing calls this directly

Calls 15

ChangeTagMethod · 0.95
GetQuestionMethod · 0.95
DeShortIDFunction · 0.92
TrFunction · 0.92
GetLangByCtxFunction · 0.92
NewEventFunction · 0.92
GetObjectEntityTagMethod · 0.80
CheckTagsIsChangeMethod · 0.80
ExistRecommendMethod · 0.80

Tested by

no test coverage detected