MCPcopy
hub / github.com/apache/answer / Info

Method Info

internal/service/question_common/question.go:254–362  ·  view source on GitHub ↗
(ctx context.Context, questionID string, loginUserID string)

Source from the content-addressed store, hash-verified

252}
253
254func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUserID string) (resp *schema.QuestionInfoResp, err error) {
255 questionInfo, has, err := qs.questionRepo.GetQuestion(ctx, questionID)
256 if err != nil {
257 return resp, err
258 }
259 questionInfo.ID = uid.DeShortID(questionInfo.ID)
260 if !has {
261 return resp, errors.NotFound(reason.QuestionNotFound)
262 }
263 resp = qs.ShowFormat(ctx, questionInfo)
264 if resp.Status == entity.QuestionStatusClosed {
265 metaInfo, err := qs.metaCommonService.GetMetaByObjectIdAndKey(ctx, questionInfo.ID, entity.QuestionCloseReasonKey)
266 if err != nil {
267 log.Error(err)
268 } else {
269 closeMsg := &schema.CloseQuestionMeta{}
270 err = json.Unmarshal([]byte(metaInfo.Value), closeMsg)
271 if err != nil {
272 log.Error("json.Unmarshal CloseQuestionMeta error", err.Error())
273 } else {
274 cfg, err := qs.configService.GetConfigByID(ctx, closeMsg.CloseType)
275 if err != nil {
276 log.Error("json.Unmarshal QuestionCloseJson error", err.Error())
277 } else {
278 reasonItem := &schema.ReasonItem{}
279 _ = json.Unmarshal(cfg.GetByteValue(), reasonItem)
280 reasonItem.Translate(cfg.Key, handler.GetLangByCtx(ctx))
281 operation := &schema.Operation{}
282 operation.Type = reasonItem.Name
283 operation.Description = reasonItem.Description
284 operation.Msg = closeMsg.CloseMsg
285 operation.Time = metaInfo.CreatedAt.Unix()
286 operation.Level = schema.OperationLevelInfo
287 resp.Operation = operation
288 }
289 }
290 }
291 }
292
293 if resp.Status != entity.QuestionStatusDeleted {
294 if resp.Tags, err = qs.tagCommon.GetObjectTag(ctx, questionID); err != nil {
295 return resp, err
296 }
297 } else {
298 revisionInfo, exist, err := qs.revisionRepo.GetLastRevisionByObjectID(ctx, questionID)
299 if err != nil {
300 log.Errorf("get revision error %s", err)
301 }
302 if exist {
303 questionWithTagsRevision := &entity.QuestionWithTagsRevision{}
304 if err = json.Unmarshal([]byte(revisionInfo.Content), questionWithTagsRevision); err != nil {
305 log.Errorf("revision parsing error %s", err)
306 return resp, nil
307 }
308 for _, tag := range questionWithTagsRevision.Tags {
309 resp.Tags = append(resp.Tags, &schema.TagResp{
310 ID: tag.ID,
311 SlugName: tag.SlugName,

Callers

nothing calls this directly

Calls 15

ShowFormatMethod · 0.95
TranslateMethod · 0.95
DeShortIDFunction · 0.92
GetLangByCtxFunction · 0.92
IsNotZeroStringFunction · 0.92
GetByteValueMethod · 0.80
GetObjectTagMethod · 0.80
SearchAnswerIDsMethod · 0.80
GetQuestionMethod · 0.65
GetConfigByIDMethod · 0.65

Tested by

no test coverage detected