MCPcopy Create free account
hub / github.com/apache/answer / parseItem

Method parseItem

internal/service/content/revision_service.go:429–492  ·  view source on GitHub ↗
(ctx context.Context, item *schema.GetRevisionResp)

Source from the content-addressed store, hash-verified

427}
428
429func (rs *RevisionService) parseItem(ctx context.Context, item *schema.GetRevisionResp) {
430 var (
431 err error
432 question entity.QuestionWithTagsRevision
433 questionInfo *schema.QuestionInfoResp
434 answer entity.Answer
435 answerInfo *schema.AnswerInfo
436 tag entity.Tag
437 tagInfo *schema.GetTagResp
438 )
439
440 shortID := handler.GetEnableShortID(ctx)
441 if shortID {
442 item.ObjectID = uid.EnShortID(item.ObjectID)
443 }
444 switch item.ObjectType {
445 case constant.ObjectTypeStrMapping["question"]:
446 err = json.Unmarshal([]byte(item.Content), &question)
447 if err != nil {
448 break
449 }
450 questionInfo = rs.questionCommon.ShowFormatWithTag(ctx, &question)
451 if shortID {
452 questionInfo.ID = uid.EnShortID(questionInfo.ID)
453 }
454 item.ContentParsed = questionInfo
455 case constant.ObjectTypeStrMapping["answer"]:
456 err = json.Unmarshal([]byte(item.Content), &answer)
457 if err != nil {
458 break
459 }
460 answerInfo = rs.answerService.ShowFormat(ctx, &answer)
461 if shortID {
462 answerInfo.ID = uid.EnShortID(answerInfo.ID)
463 answerInfo.QuestionID = uid.EnShortID(answerInfo.QuestionID)
464 }
465 item.ContentParsed = answerInfo
466 case constant.ObjectTypeStrMapping["tag"]:
467 err = json.Unmarshal([]byte(item.Content), &tag)
468 if err != nil {
469 break
470 }
471 tagInfo = &schema.GetTagResp{
472 TagID: tag.ID,
473 CreatedAt: tag.CreatedAt.Unix(),
474 UpdatedAt: tag.UpdatedAt.Unix(),
475 SlugName: tag.SlugName,
476 DisplayName: tag.DisplayName,
477 OriginalText: tag.OriginalText,
478 ParsedText: tag.ParsedText,
479 FollowCount: tag.FollowCount,
480 QuestionCount: tag.QuestionCount,
481 Recommend: tag.Recommend,
482 Reserved: tag.Reserved,
483 }
484 tagInfo.GetExcerpt()
485 item.ContentParsed = tagInfo
486 }

Callers 3

RevisionAuditMethod · 0.95
GetRevisionListMethod · 0.95

Calls 5

GetEnableShortIDFunction · 0.92
EnShortIDFunction · 0.92
ShowFormatWithTagMethod · 0.80
ShowFormatMethod · 0.45
GetExcerptMethod · 0.45

Tested by

no test coverage detected