@@ -74,18 +74,38 @@ func foundMatch(tx *redis.Tx, ctx context.Context, currentUser *models.MatchRequ
74
74
}
75
75
76
76
var matchedTopics []string
77
- for _ , topic := range currentUser .Topics {
77
+ if len (currentUser .Topics ) == 0 || len (matchedUser .Topics ) == 0 {
78
+ // Ensure that matchedTopics will not be empty unless both users are empty
79
+ for _ , topic := range currentUser .Topics {
80
+ matchedTopics = append (matchedTopics , topic )
81
+ }
78
82
for _ , otherTopic := range matchedUser .Topics {
79
- if topic == otherTopic {
80
- matchedTopics = append (matchedTopics , topic )
83
+ matchedTopics = append (matchedTopics , otherTopic )
84
+ }
85
+ } else {
86
+ for _ , topic := range currentUser .Topics {
87
+ for _ , otherTopic := range matchedUser .Topics {
88
+ if topic == otherTopic {
89
+ matchedTopics = append (matchedTopics , topic )
90
+ }
81
91
}
82
92
}
83
93
}
84
94
var matchedDifficulties []string
85
- for _ , topic := range currentUser .Difficulties {
86
- for _ , otherTopic := range matchedUser .Difficulties {
87
- if topic == otherTopic {
88
- matchedDifficulties = append (matchedDifficulties , topic )
95
+ if len (currentUser .Difficulties ) == 0 || len (matchedUser .Difficulties ) == 0 {
96
+ // Ensure that matchedDifficulties will not be empty unless both users are empty
97
+ for _ , diff := range currentUser .Difficulties {
98
+ matchedDifficulties = append (matchedDifficulties , diff )
99
+ }
100
+ for _ , otherDiff := range matchedUser .Difficulties {
101
+ matchedDifficulties = append (matchedDifficulties , otherDiff )
102
+ }
103
+ } else {
104
+ for _ , diff := range currentUser .Difficulties {
105
+ for _ , otherDiff := range matchedUser .Difficulties {
106
+ if diff == otherDiff {
107
+ matchedDifficulties = append (matchedDifficulties , diff )
108
+ }
89
109
}
90
110
}
91
111
}
@@ -200,7 +220,7 @@ func doDifficultyMatching(tx *redis.Tx, ctx context.Context, currentUser *models
200
220
if err != nil {
201
221
return nil , err
202
222
}
203
- if len (otherUser .Topics ) == 0 {
223
+ if len (otherUser .Difficulties ) == 0 {
204
224
foundUsers = append (foundUsers , otherUsername )
205
225
}
206
226
0 commit comments