@@ -74,18 +74,38 @@ func foundMatch(tx *redis.Tx, ctx context.Context, currentUser *models.MatchRequ
7474 }
7575
7676 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+ }
7882 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+ }
8191 }
8292 }
8393 }
8494 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+ }
89109 }
90110 }
91111 }
@@ -200,7 +220,7 @@ func doDifficultyMatching(tx *redis.Tx, ctx context.Context, currentUser *models
200220 if err != nil {
201221 return nil , err
202222 }
203- if len (otherUser .Topics ) == 0 {
223+ if len (otherUser .Difficulties ) == 0 {
204224 foundUsers = append (foundUsers , otherUsername )
205225 }
206226
0 commit comments