Skip to content

Commit f268332

Browse files
committed
feat: update docker and env
1 parent 2ff03c3 commit f268332

File tree

11 files changed

+34
-39
lines changed

11 files changed

+34
-39
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
MATCHING_SERVICE_PORT: ${{ vars.MATCHING_SERVICE_PORT }}
3737
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
3838
REDIS_URL: ${{ vars.REDIS_URL }}
39+
QUESTION_SERVICE_GRPC_URL: ${{ vars.QUESTION_SERVICE_GPRC_URL }}
3940
run: |
4041
cd ./apps/frontend
4142
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env
@@ -56,6 +57,7 @@ jobs:
5657
echo "MATCH_TIMEOUT=$MATCHING_SERVICE_TIMEOUT" >> .env
5758
echo "JWT_SECRET=$JWT_SECRET" >> .env
5859
echo "REDIS_URL=$REDIS_URL" >> .env
60+
echo "QUESTION_SERVICE_GRPC_URL=$QUESTION_SERVICE_GRPC_URL" >> .env
5961
6062
- name: Create Database Credential Files
6163
env:

apps/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Once running, you can access:
5656

5757
- The **frontend** at http://localhost:3000
5858
- The **user service** at http://localhost:3001
59-
- The **question service** at http://localhost:8080
59+
- The **question service** at http://localhost:8080 (REST) and http://localhost:50051 (gRPC)
6060
- The **matching service** at http://localhost:8081
6161
- The **redis service** at http://localhost:6379
6262

apps/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ services:
3131
dockerfile: Dockerfile
3232
ports:
3333
- 8080:8080
34+
- 50051:50051
3435
env_file:
3536
- ./question-service/.env
3637
networks:

apps/frontend/src/app/matching/modalContent/FindMatchContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ const DifficultySelector: React.FC<DifficultySelectorProps> = ({ selectedDifficu
9494
<Tag.CheckableTag
9595
className={`difficulty-tag ${difficultyOption.value}-tag`}
9696
key={difficultyOption.value}
97-
checked={selectedDifficulties.includes(difficultyOption.label)}
98-
onChange={() => handleChange(difficultyOption.label)}
97+
checked={selectedDifficulties.includes(difficultyOption.value)}
98+
onChange={() => handleChange(difficultyOption.value)}
9999
>
100100
{difficultyOption.label}
101101
</Tag.CheckableTag>

apps/frontend/src/app/services/use-matching.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ export type MatchRequestParams = {
1717
}
1818

1919
export type MatchFoundResponse = {
20-
type: "match_found",
21-
matchId: number,
22-
partnerId: number,
23-
partnerName: string,
24-
} | {
25-
type: "match_found",
26-
matchId: string,
20+
type: "match_question_found",
21+
match_id: string,
2722
user: string,
28-
matchedUser: string,
29-
topic: string | string[],
30-
difficulty: string
23+
matched_user: string,
24+
matched_topics: string[],
25+
question_doc_ref_id: string,
26+
question_name: string,
27+
question_difficulty: string,
28+
question_topics: string[],
3129
}
3230

3331
export type MatchTimeoutResponse = {
@@ -61,7 +59,7 @@ export default function useMatching(): MatchState {
6159
return;
6260
}
6361

64-
if (responseJson.type == "match_found") {
62+
if (responseJson.type == "match_question_found") {
6563
setIsSocket(false);
6664

6765
const info: MatchInfo = parseInfoFromResponse(responseJson);
@@ -136,20 +134,9 @@ export default function useMatching(): MatchState {
136134
}
137135

138136
function parseInfoFromResponse(responseJson: MatchFoundResponse): MatchInfo {
139-
// test whether old or new
140-
if ("partnerId" in responseJson) {
141-
return {
142-
matchId: responseJson.matchId?.toString() ?? "unknown",
143-
partnerId: responseJson.partnerId?.toString() ?? "unknown",
144-
partnerName: responseJson.partnerName ?? "unknown",
145-
myName: "unknown",
146-
};
147-
} else {
148-
return {
149-
matchId: responseJson.matchId?.toString() ?? "unknown",
150-
partnerId: "unknown",
151-
partnerName: responseJson.matchedUser ?? "unknown",
152-
myName: responseJson.user ?? "unknown",
153-
};
154-
}
137+
return {
138+
matchId: responseJson.match_id?.toString() ?? "unknown",
139+
partnerName: responseJson.matched_user ?? "unknown",
140+
myName: responseJson.user ?? "unknown",
141+
};
155142
}

apps/frontend/src/contexts/websocketcontext.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export type SocketState = {
1515
};
1616
export type MatchInfo = {
1717
matchId: string;
18-
partnerId: string;
1918
myName: string;
2019
partnerName: string;
2120
}

apps/matching-service/.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ PORT=8081
22
MATCH_TIMEOUT=30
33
JWT_SECRET=you-can-replace-this-with-your-own-secret
44

5-
# if you are NOT USING docker, use the below url
5+
# If you are NOT USING docker, use the below variables
66
REDIS_URL=localhost:6379
7+
QUESTION_SERVICE_GRPC_URL=localhost:50051
78

8-
# if you are USING docker, use the below url
9+
# If you are USING docker, use the below variables
910
# REDIS_URL=redis-container:6379
11+
# QUESTION_SERVICE_GRPC_URL=question-service:50051

apps/matching-service/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Client sends matching parameters:
7575
{
7676
"type": "match_request",
7777
"topics": ["Algorithms", "Arrays"],
78-
"difficulties": ["Easy", "Medium"],
78+
"difficulties": ["easy", "medium"],
7979
"username": "1f0myn"
8080
}
8181
```
@@ -153,3 +153,5 @@ docker run -d --name redis-container --network redis-go-network redis
153153
```bash
154154
docker run -d -p 8081:8081 --name go-app-container --network redis-go-network match-go-app
155155
```
156+
157+
**NOTE:** As there is a dependency on the question-service to return the found questions, the matching-service does not work fully unless the question-service is present.

apps/matching-service/servers/grpc.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package servers
33
import (
44
"log"
55
pb "matching-service/proto"
6+
"os"
67

78
"google.golang.org/grpc"
89
"google.golang.org/grpc/credentials/insecure"
@@ -13,12 +14,13 @@ var (
1314
)
1415

1516
func InitGrpcServer() *grpc.ClientConn {
17+
questionServiceAddr := os.Getenv("QUESTION_SERVICE_GRPC_URL")
1618
// Dial the server
17-
conn, err := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
19+
conn, err := grpc.NewClient(questionServiceAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
1820
if err != nil {
19-
log.Fatalf("Did not connect: %v", err)
21+
log.Fatalf("Did not connect to %v: %v", questionServiceAddr, err)
2022
} else {
21-
log.Println("Connected to Grpc server at :50051")
23+
log.Println("Connected to Grpc server at %v", questionServiceAddr)
2224
}
2325

2426
// Create a new client for the ExampleService

apps/question-service/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ COPY . .
1111

1212
RUN go build -v -o /usr/local/bin/app ./main.go
1313

14-
EXPOSE 8080
14+
EXPOSE 8080 50051
1515

1616
CMD ["app"]

0 commit comments

Comments
 (0)