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

Method Get

internal/service/content/answer_service.go:536–597  ·  view source on GitHub ↗
(ctx context.Context, answerID, loginUserID string, isAdminModerator bool)

Source from the content-addressed store, hash-verified

534}
535
536func (as *AnswerService) Get(ctx context.Context, answerID, loginUserID string, isAdminModerator bool) (*schema.AnswerInfo, *schema.QuestionInfoResp, bool, error) {
537 answerInfo, has, err := as.answerRepo.GetByID(ctx, answerID)
538 if err != nil {
539 return nil, nil, has, err
540 }
541 if !has {
542 return nil, nil, false, nil
543 }
544 question, exist, err := as.questionRepo.GetQuestion(ctx, answerInfo.QuestionID)
545 if err != nil {
546 return nil, nil, has, err
547 }
548 if !exist {
549 return nil, nil, false, errors.NotFound(reason.AnswerNotFound)
550 }
551 if (question.Status == entity.QuestionStatusDeleted ||
552 question.Status == entity.QuestionStatusPending ||
553 question.Show == entity.QuestionHide) &&
554 !isAdminModerator && question.UserID != loginUserID {
555 return nil, nil, false, errors.NotFound(reason.AnswerNotFound)
556 }
557 info := as.ShowFormat(ctx, answerInfo)
558 // todo questionFunc
559 questionInfo, err := as.questionCommon.Info(ctx, answerInfo.QuestionID, loginUserID)
560 if err != nil {
561 return nil, nil, has, err
562 }
563 // todo UserFunc
564
565 userIds := make([]string, 0)
566 userIds = append(userIds, answerInfo.UserID)
567 userIds = append(userIds, answerInfo.LastEditUserID)
568 userInfoMap, err := as.userCommon.BatchUserBasicInfoByID(ctx, userIds)
569 if err != nil {
570 return nil, nil, has, err
571 }
572
573 _, ok := userInfoMap[answerInfo.UserID]
574 if ok {
575 info.UserInfo = userInfoMap[answerInfo.UserID]
576 }
577 _, ok = userInfoMap[answerInfo.LastEditUserID]
578 if ok {
579 info.UpdateUserInfo = userInfoMap[answerInfo.LastEditUserID]
580 }
581
582 if loginUserID == "" {
583 return info, questionInfo, has, nil
584 }
585
586 info.VoteStatus = as.voteRepo.GetVoteStatus(ctx, answerID, loginUserID)
587
588 collectedMap, err := as.collectionCommon.SearchObjectCollected(ctx, loginUserID, []string{answerInfo.ID})
589 if err != nil {
590 return nil, nil, has, err
591 }
592 if len(collectedMap) > 0 {
593 info.Collected = true

Callers 15

AddQuestionByAnswerMethod · 0.45
GetAnswerInfoMethod · 0.45
AddAnswerMethod · 0.45
UpdateAnswerMethod · 0.45
GetAIModelsMethod · 0.45
defaultLoginConfigFunction · 0.45
deactivatePluginFunction · 0.45
GetUserInfoFromContextFunction · 0.45
GetUserIsAdminModeratorFunction · 0.45
createDefaultValidatorFunction · 0.45
getObjectTagByFieldNameFunction · 0.45
GetEnableShortIDFunction · 0.45

Calls 7

ShowFormatMethod · 0.95
GetByIDMethod · 0.65
GetQuestionMethod · 0.65
InfoMethod · 0.65
GetVoteStatusMethod · 0.65
SearchObjectCollectedMethod · 0.65

Tested by

no test coverage detected