(ctx context.Context, req *schema.CloseQuestionReq)
| 152 | } |
| 153 | |
| 154 | func (qs *QuestionService) CloseQuestion(ctx context.Context, req *schema.CloseQuestionReq) error { |
| 155 | questionInfo, has, err := qs.questionRepo.GetQuestion(ctx, req.ID) |
| 156 | if err != nil { |
| 157 | return err |
| 158 | } |
| 159 | if !has { |
| 160 | return nil |
| 161 | } |
| 162 | |
| 163 | cf, err := qs.configService.GetConfigByID(ctx, req.CloseType) |
| 164 | if err != nil || cf == nil { |
| 165 | return errors.BadRequest(reason.ReportNotFound) |
| 166 | } |
| 167 | if cf.Key == constant.ReasonADuplicate && !checker.IsURL(req.CloseMsg) { |
| 168 | return errors.BadRequest(reason.InvalidURLError) |
| 169 | } |
| 170 | |
| 171 | questionInfo.Status = entity.QuestionStatusClosed |
| 172 | err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo.ID, questionInfo.Status) |
| 173 | if err != nil { |
| 174 | return err |
| 175 | } |
| 176 | |
| 177 | closeMeta, _ := json.Marshal(schema.CloseQuestionMeta{ |
| 178 | CloseType: req.CloseType, |
| 179 | CloseMsg: req.CloseMsg, |
| 180 | }) |
| 181 | err = qs.metaService.AddMeta(ctx, req.ID, entity.QuestionCloseReasonKey, string(closeMeta)) |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | if cf.Key == constant.ReasonADuplicate { |
| 186 | qs.questioncommon.AddQuestionLinkForCloseReason(ctx, questionInfo, req.CloseMsg) |
| 187 | } |
| 188 | |
| 189 | qs.activityQueueService.Send(ctx, &schema.ActivityMsg{ |
| 190 | UserID: req.UserID, |
| 191 | ObjectID: questionInfo.ID, |
| 192 | OriginalObjectID: questionInfo.ID, |
| 193 | ActivityTypeKey: constant.ActQuestionClosed, |
| 194 | }) |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | // ReopenQuestion reopen question |
| 199 | func (qs *QuestionService) ReopenQuestion(ctx context.Context, req *schema.ReopenQuestionReq) error { |
nothing calls this directly
no test coverage detected