(ctx context.Context, answerID, loginUserID string, isAdminModerator bool)
| 534 | } |
| 535 | |
| 536 | func (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 |
no test coverage detected