SimilarQuestion
(ctx context.Context, questionID string, loginUserID string)
| 1437 | |
| 1438 | // SimilarQuestion |
| 1439 | func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID string, loginUserID string) ([]*schema.QuestionPageResp, int64, error) { |
| 1440 | question, err := qs.questioncommon.Info(ctx, questionID, loginUserID) |
| 1441 | if err != nil { |
| 1442 | return nil, 0, nil |
| 1443 | } |
| 1444 | tagNames := make([]string, 0, len(question.Tags)) |
| 1445 | for _, tag := range question.Tags { |
| 1446 | tagNames = append(tagNames, tag.SlugName) |
| 1447 | } |
| 1448 | search := &schema.QuestionPageReq{} |
| 1449 | search.OrderCond = "hot" |
| 1450 | search.Page = 0 |
| 1451 | search.PageSize = 6 |
| 1452 | if len(tagNames) > 0 { |
| 1453 | search.Tag = tagNames[0] |
| 1454 | } |
| 1455 | search.LoginUserID = loginUserID |
| 1456 | similarQuestions, _, err := qs.GetQuestionPage(ctx, search) |
| 1457 | if err != nil { |
| 1458 | return nil, 0, err |
| 1459 | } |
| 1460 | var result []*schema.QuestionPageResp |
| 1461 | for _, v := range similarQuestions { |
| 1462 | if uid.DeShortID(v.ID) != questionID { |
| 1463 | result = append(result, v) |
| 1464 | } |
| 1465 | } |
| 1466 | return result, int64(len(result)), nil |
| 1467 | } |
| 1468 | |
| 1469 | // GetQuestionPage query questions page |
| 1470 | func (qs *QuestionService) GetQuestionPage(ctx context.Context, req *schema.QuestionPageReq) ( |
nothing calls this directly
no test coverage detected