(ctx context.Context, questionList []*entity.Question, loginUserID string)
| 465 | } |
| 466 | |
| 467 | func (qs *QuestionCommon) FormatQuestions(ctx context.Context, questionList []*entity.Question, loginUserID string) ([]*schema.QuestionInfoResp, error) { |
| 468 | list := make([]*schema.QuestionInfoResp, 0) |
| 469 | objectIds := make([]string, 0) |
| 470 | userIds := make([]string, 0) |
| 471 | |
| 472 | for _, questionInfo := range questionList { |
| 473 | item := qs.ShowFormat(ctx, questionInfo) |
| 474 | list = append(list, item) |
| 475 | objectIds = append(objectIds, item.ID) |
| 476 | userIds = append(userIds, item.UserID, item.LastEditUserID, item.LastAnsweredUserID) |
| 477 | } |
| 478 | tagsMap, err := qs.tagCommon.BatchGetObjectTag(ctx, objectIds) |
| 479 | if err != nil { |
| 480 | return list, err |
| 481 | } |
| 482 | |
| 483 | userInfoMap, err := qs.userCommon.BatchUserBasicInfoByID(ctx, userIds) |
| 484 | if err != nil { |
| 485 | return list, err |
| 486 | } |
| 487 | |
| 488 | for _, item := range list { |
| 489 | item.Tags = tagsMap[item.ID] |
| 490 | item.UserInfo = userInfoMap[item.UserID] |
| 491 | item.UpdateUserInfo = userInfoMap[item.LastEditUserID] |
| 492 | item.LastAnsweredUserInfo = userInfoMap[item.LastAnsweredUserID] |
| 493 | } |
| 494 | if loginUserID == "" { |
| 495 | return list, nil |
| 496 | } |
| 497 | |
| 498 | collectedMap, err := qs.collectionCommon.SearchObjectCollected(ctx, loginUserID, objectIds) |
| 499 | if err != nil { |
| 500 | return nil, err |
| 501 | } |
| 502 | for _, item := range list { |
| 503 | item.Collected = collectedMap[item.ID] |
| 504 | } |
| 505 | return list, nil |
| 506 | } |
| 507 | |
| 508 | // RemoveQuestion delete question |
| 509 | func (qs *QuestionCommon) RemoveQuestion(ctx context.Context, req *schema.RemoveQuestionReq) (err error) { |
no test coverage detected