Skip to content

Commit 16a2023

Browse files
committed
feat: return docrefid
1 parent 7b37824 commit 16a2023

File tree

6 files changed

+49
-39
lines changed

6 files changed

+49
-39
lines changed

apps/matching-service/models/match.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type MatchQuestionFound struct {
2222
User string `json:"user"`
2323
MatchedUser string `json:"matched_user"`
2424
MatchedTopics []string `json:"matched_topics"`
25-
QuestionID int64 `json:"question_id"`
25+
QuestionDocRefID string `json:"question_doc_ref_id"`
2626
QuestionName string `json:"question_name"`
2727
QuestionDifficulty string `json:"question_difficulty"`
2828
QuestionTopics []string `json:"question_topics"`

apps/matching-service/models/question.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type MatchQuestionRequest struct {
66
}
77

88
type QuestionFound struct {
9-
QuestionID int64 `json:"question_id"`
9+
QuestionDocRefID string `json:"question_doc_ref_id"`
1010
QuestionName string `json:"question_name"`
1111
QuestionDifficulty string `json:"question_difficulty"`
1212
QuestionTopics []string `json:"question_topics"`

apps/matching-service/processes/performmatches.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func completeMatch(tx *redis.Tx, ctx context.Context, matchFound *models.MatchFo
7777
matchQuestionFound := queryQuestionService(ctx, matchFound)
7878

7979
log.Printf("Match %v: Question %v found with topics: %v and difficulty %v",
80-
matchFound.MatchID, matchQuestionFound.QuestionID,
80+
matchFound.MatchID, matchQuestionFound.QuestionDocRefID,
8181
matchQuestionFound.QuestionTopics, matchQuestionFound.QuestionDifficulty)
8282

8383
currentUsername := matchFound.User
@@ -119,7 +119,7 @@ func queryQuestionService(ctx context.Context, matchFound *models.MatchFound) *m
119119
User: matchFound.User,
120120
MatchedUser: matchFound.MatchedUser,
121121
MatchedTopics: matchFound.MatchedTopics,
122-
QuestionID: question.QuestionId,
122+
QuestionDocRefID: question.QuestionName,
123123
QuestionName: question.QuestionName,
124124
QuestionDifficulty: question.QuestionDifficulty,
125125
QuestionTopics: question.QuestionTopics,

apps/proto/questionmatching.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ message MatchQuestionRequest {
1010
}
1111

1212
message QuestionFound {
13-
int64 question_id = 1;
13+
string question_doc_ref_id = 1;
1414
string question_name = 2;
1515
string question_difficulty = 3;
1616
repeated string question_topics = 4;

apps/proto/questionmatching/questionmatching.pb.go

Lines changed: 27 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/question-service/handlers/findmatchingquestion.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,33 @@ func (s *GrpcServer) FindMatchingQuestion(ctx context.Context, req *pb.MatchQues
6767
}
6868

6969
// 5b. Retrieve random question from potential questions
70+
question, err := retrieveRandomQuestion(docs)
71+
if err != nil {
72+
return nil, err
73+
}
74+
75+
return &pb.QuestionFound{
76+
QuestionDocRefId: question.DocRefID,
77+
QuestionName: question.Title,
78+
QuestionDifficulty: question.Complexity.String(),
79+
QuestionTopics: question.Categories,
80+
}, nil
81+
}
82+
83+
// Retrieve the document at the random offset
84+
85+
func retrieveRandomQuestion(docs []*firestore.DocumentSnapshot) (*models.Question, error) {
7086
// Generate a random offset
7187
randomOffset := rand.Intn(len(docs))
7288

73-
// Retrieve the document at the random offset
7489
doc := docs[randomOffset]
7590
var question models.Question
7691
if err := doc.DataTo(&question); err != nil {
7792
return nil, err
7893

7994
}
8095
question.DocRefID = doc.Ref.ID
81-
82-
return &pb.QuestionFound{
83-
QuestionId: question.ID,
84-
QuestionName: question.Title,
85-
QuestionDifficulty: question.Complexity.String(),
86-
QuestionTopics: question.Categories,
87-
}, nil
96+
return &question, nil
8897
}
8998

9099
func queryTopicAndDifficultyQuestion(client *firestore.Client, ctx context.Context, topics []string, difficulties []models.ComplexityType) ([]*firestore.DocumentSnapshot, error) {

0 commit comments

Comments
 (0)