1
+ //this file is deprecated
1
2
package mappings
2
3
3
4
import (
@@ -7,25 +8,25 @@ import (
7
8
"fmt"
8
9
"io"
9
10
"matching-service/models"
10
-
11
11
)
12
12
13
- //TODO: consider using redis to store this information instead
13
+ // TODO: consider using redis to store this information instead
14
14
type Mappings struct {
15
- Topics map [string ][]string
15
+ Topics map [string ][]string
16
16
Difficulty map [string ]string
17
17
}
18
18
19
19
func CreateMappings () * Mappings {
20
20
return & Mappings {
21
- Topics : make (map [string ][]string ),
21
+ Topics : make (map [string ][]string ),
22
22
Difficulty : make (map [string ]string ),
23
23
}
24
24
}
25
- //TODO: implement logic to implement TTL for values
26
- //logic to find matching categories and generates a room id for the 2 users
27
- func (db * Mappings ) HandleRequest (request models.Requests ) (* models.Room , error ){
28
- for user1 , topics := range db .Topics {
25
+
26
+ // TODO: implement logic to implement TTL for values
27
+ // logic to find matching categories and generates a room id for the 2 users
28
+ func (db * Mappings ) HandleRequest (request models.IncomingRequests ) (* models.Room , error ) {
29
+ for user1 , topics := range db .Topics {
29
30
if difficulty , exists := db .Difficulty [user1 ]; ! exists {
30
31
return nil , fmt .Errorf ("user %s only exists in topics store and not in difficulty store" , user1 )
31
32
} else if difficulty != request .Difficulty {
@@ -37,8 +38,8 @@ func (db *Mappings) HandleRequest(request models.Requests) (*models.Room, error)
37
38
// user1 does not match with this user
38
39
if len (overlapping ) == 0 {
39
40
continue
40
- }
41
-
41
+ }
42
+
42
43
//match found, generate room Id and return the room
43
44
if roomId , err := generateRoomId (); err != nil {
44
45
return nil , err
@@ -48,20 +49,20 @@ func (db *Mappings) HandleRequest(request models.Requests) (*models.Room, error)
48
49
delete (db .Difficulty , user1 )
49
50
50
51
return & models.Room {
51
- RoomId : roomId ,
52
- User1 : user1 ,
53
- User2 : request .UserId ,
54
- TopicTags : overlapping ,
52
+ RoomId : roomId ,
53
+ User1 : user1 ,
54
+ User2 : request .UserId ,
55
+ TopicTags : overlapping ,
55
56
Difficulty : request .Difficulty ,
56
57
}, nil
57
- }
58
+ }
58
59
}
59
60
60
61
//no match found
61
62
//add user2 to the mappings
62
63
db .Topics [request .UserId ] = request .TopicTags
63
64
db .Difficulty [request .UserId ] = request .Difficulty
64
-
65
+
65
66
return nil , nil
66
67
}
67
68
@@ -76,22 +77,22 @@ func generateRoomId() (string, error) {
76
77
}
77
78
78
79
func findOverLap (user1 []string , user2 []string ) []string {
79
-
80
+
80
81
stringMap := make (map [string ]bool )
81
- var commonStrings []string
82
-
83
- // Store each string from slice1 in the map
84
- for _ , topic := range user1 {
85
- stringMap [topic ] = true
86
- }
87
-
88
- // Iterate over slice2 and check for common strings
89
- for _ , topic := range user2 {
90
- if stringMap [topic ] {
91
- commonStrings = append (commonStrings , topic )
92
- delete (stringMap , topic ) // Remove to avoid duplicates in result
93
- }
94
- }
95
-
96
- return commonStrings
97
- }
82
+ var commonStrings []string
83
+
84
+ // Store each string from slice1 in the map
85
+ for _ , topic := range user1 {
86
+ stringMap [topic ] = true
87
+ }
88
+
89
+ // Iterate over slice2 and check for common strings
90
+ for _ , topic := range user2 {
91
+ if stringMap [topic ] {
92
+ commonStrings = append (commonStrings , topic )
93
+ delete (stringMap , topic ) // Remove to avoid duplicates in result
94
+ }
95
+ }
96
+
97
+ return commonStrings
98
+ }
0 commit comments