diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d2a1ad306..877de8eaf8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,6 +36,7 @@ jobs: MATCHING_SERVICE_PORT: ${{ vars.MATCHING_SERVICE_PORT }} MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }} REDIS_URL: ${{ vars.REDIS_URL }} + QUESTION_SERVICE_GRPC_URL: ${{ vars.QUESTION_SERVICE_GPRC_URL }} run: | cd ./apps/frontend echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env @@ -56,6 +57,7 @@ jobs: echo "MATCH_TIMEOUT=$MATCHING_SERVICE_TIMEOUT" >> .env echo "JWT_SECRET=$JWT_SECRET" >> .env echo "REDIS_URL=$REDIS_URL" >> .env + echo "QUESTION_SERVICE_GRPC_URL=$QUESTION_SERVICE_GRPC_URL" >> .env - name: Create Database Credential Files env: diff --git a/apps/README.md b/apps/README.md index 18525dd4f6..ae12a36fc1 100644 --- a/apps/README.md +++ b/apps/README.md @@ -56,7 +56,7 @@ Once running, you can access: - The **frontend** at http://localhost:3000 - The **user service** at http://localhost:3001 -- The **question service** at http://localhost:8080 +- The **question service** at http://localhost:8080 (REST) and http://localhost:50051 (gRPC) - The **matching service** at http://localhost:8081 - The **redis service** at http://localhost:6379 diff --git a/apps/docker-compose.yml b/apps/docker-compose.yml index e69e2bcc65..a8ee1986f9 100644 --- a/apps/docker-compose.yml +++ b/apps/docker-compose.yml @@ -31,6 +31,7 @@ services: dockerfile: Dockerfile ports: - 8080:8080 + - 50051:50051 env_file: - ./question-service/.env networks: diff --git a/apps/frontend/src/app/matching/modalContent/FindMatchContent.tsx b/apps/frontend/src/app/matching/modalContent/FindMatchContent.tsx index ac65cbe033..383f049385 100644 --- a/apps/frontend/src/app/matching/modalContent/FindMatchContent.tsx +++ b/apps/frontend/src/app/matching/modalContent/FindMatchContent.tsx @@ -94,8 +94,8 @@ const DifficultySelector: React.FC = ({ selectedDifficu handleChange(difficultyOption.label)} + checked={selectedDifficulties.includes(difficultyOption.value)} + onChange={() => handleChange(difficultyOption.value)} > {difficultyOption.label} diff --git a/apps/frontend/src/app/services/use-matching.ts b/apps/frontend/src/app/services/use-matching.ts index ce9d463b53..4a37c9f153 100644 --- a/apps/frontend/src/app/services/use-matching.ts +++ b/apps/frontend/src/app/services/use-matching.ts @@ -17,17 +17,15 @@ export type MatchRequestParams = { } export type MatchFoundResponse = { - type: "match_found", - matchId: number, - partnerId: number, - partnerName: string, -} | { - type: "match_found", - matchId: string, + type: "match_question_found", + match_id: string, user: string, - matchedUser: string, - topic: string | string[], - difficulty: string + matched_user: string, + matched_topics: string[], + question_doc_ref_id: string, + question_name: string, + question_difficulty: string, + question_topics: string[], } export type MatchTimeoutResponse = { @@ -61,7 +59,7 @@ export default function useMatching(): MatchState { return; } - if (responseJson.type == "match_found") { + if (responseJson.type == "match_question_found") { setIsSocket(false); const info: MatchInfo = parseInfoFromResponse(responseJson); @@ -136,20 +134,9 @@ export default function useMatching(): MatchState { } function parseInfoFromResponse(responseJson: MatchFoundResponse): MatchInfo { - // test whether old or new - if ("partnerId" in responseJson) { - return { - matchId: responseJson.matchId?.toString() ?? "unknown", - partnerId: responseJson.partnerId?.toString() ?? "unknown", - partnerName: responseJson.partnerName ?? "unknown", - myName: "unknown", - }; - } else { - return { - matchId: responseJson.matchId?.toString() ?? "unknown", - partnerId: "unknown", - partnerName: responseJson.matchedUser ?? "unknown", - myName: responseJson.user ?? "unknown", - }; - } + return { + matchId: responseJson.match_id?.toString() ?? "unknown", + partnerName: responseJson.matched_user ?? "unknown", + myName: responseJson.user ?? "unknown", + }; } diff --git a/apps/frontend/src/contexts/websocketcontext.tsx b/apps/frontend/src/contexts/websocketcontext.tsx index fe0c95624d..84893c15ed 100644 --- a/apps/frontend/src/contexts/websocketcontext.tsx +++ b/apps/frontend/src/contexts/websocketcontext.tsx @@ -15,7 +15,6 @@ export type SocketState = { }; export type MatchInfo = { matchId: string; - partnerId: string; myName: string; partnerName: string; } diff --git a/apps/matching-service/.env.example b/apps/matching-service/.env.example index 8fc9a4032a..50dc113f63 100644 --- a/apps/matching-service/.env.example +++ b/apps/matching-service/.env.example @@ -2,8 +2,10 @@ PORT=8081 MATCH_TIMEOUT=30 JWT_SECRET=you-can-replace-this-with-your-own-secret -# if you are NOT USING docker, use the below url +# If you are NOT USING docker, use the below variables REDIS_URL=localhost:6379 +QUESTION_SERVICE_GRPC_URL=localhost:50051 -# if you are USING docker, use the below url +# If you are USING docker, use the below variables # REDIS_URL=redis-container:6379 +# QUESTION_SERVICE_GRPC_URL=question-service:50051 diff --git a/apps/matching-service/README.md b/apps/matching-service/README.md index 90935e71ff..92b957c7b0 100644 --- a/apps/matching-service/README.md +++ b/apps/matching-service/README.md @@ -75,7 +75,7 @@ Client sends matching parameters: { "type": "match_request", "topics": ["Algorithms", "Arrays"], - "difficulties": ["Easy", "Medium"], + "difficulties": ["easy", "medium"], "username": "1f0myn" } ``` @@ -153,3 +153,5 @@ docker run -d --name redis-container --network redis-go-network redis ```bash docker run -d -p 8081:8081 --name go-app-container --network redis-go-network match-go-app ``` + +**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. diff --git a/apps/matching-service/servers/grpc.go b/apps/matching-service/servers/grpc.go index c8f82fdc6d..a6a2aac507 100644 --- a/apps/matching-service/servers/grpc.go +++ b/apps/matching-service/servers/grpc.go @@ -3,6 +3,7 @@ package servers import ( "log" pb "matching-service/proto" + "os" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -13,12 +14,13 @@ var ( ) func InitGrpcServer() *grpc.ClientConn { + questionServiceAddr := os.Getenv("QUESTION_SERVICE_GRPC_URL") // Dial the server - conn, err := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.NewClient(questionServiceAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - log.Fatalf("Did not connect: %v", err) + log.Fatalf("Did not connect to %v: %v", questionServiceAddr, err) } else { - log.Println("Connected to Grpc server at :50051") + log.Println("Connected to Grpc server at %v", questionServiceAddr) } // Create a new client for the ExampleService diff --git a/apps/question-service/Dockerfile b/apps/question-service/Dockerfile index c2a9e0836b..0f7b9b698a 100644 --- a/apps/question-service/Dockerfile +++ b/apps/question-service/Dockerfile @@ -11,6 +11,6 @@ COPY . . RUN go build -v -o /usr/local/bin/app ./main.go -EXPOSE 8080 +EXPOSE 8080 50051 CMD ["app"] diff --git a/apps/question-service/README.md b/apps/question-service/README.md index 99ed749159..3045231030 100644 --- a/apps/question-service/README.md +++ b/apps/question-service/README.md @@ -58,7 +58,7 @@ docker build -t question-service . ``` ```bash -docker run -p 8080:8080 --env-file .env -d question-service +docker run -p 8080:8080 -p 50051:50051 --env-file .env -d question-service ``` The server will be available at http://localhost:8080.