Skip to content

Commit dda9217

Browse files
committed
Fix question id not retrieving bug
1 parent 9b67930 commit dda9217

File tree

3 files changed

+49
-57
lines changed

3 files changed

+49
-57
lines changed

docker-compose.yml

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
services:
2+
api-gateway:
3+
image: nginx:1.26
4+
volumes:
5+
- ./api-gateway/templates:/etc/nginx/templates
6+
- ./api-gateway/nginx.conf:/etc/nginx/nginx.conf
7+
ports:
8+
- $API_GATEWAY_PORT:$API_GATEWAY_PORT
9+
environment:
10+
- PORT=$API_GATEWAY_PORT
11+
- FRONTEND_PORT=$FRONTEND_PORT
12+
- USER_SVC_PORT=$USER_SVC_PORT
13+
- QUESTION_SVC_PORT=$QUESTION_SVC_PORT
14+
- MATCHING_SVC_PORT=$MATCHING_SVC_PORT
15+
- COLLAB_SVC_PORT=$COLLAB_SVC_PORT
16+
depends_on:
17+
- frontend
18+
- user-service
19+
- question-service
20+
- matching-service
21+
- collab-service
22+
223
frontend:
324
build:
425
context: ./frontend
@@ -7,10 +28,8 @@ services:
728
- API_GATEWAY_PORT=$API_GATEWAY_PORT
829
environment:
930
- PORT=$FRONTEND_PORT
10-
ports:
11-
- $FRONTEND_PORT:$FRONTEND_PORT
12-
networks:
13-
- hidden
31+
expose:
32+
- $FRONTEND_PORT
1433

1534
question-service:
1635
build:
@@ -19,10 +38,8 @@ services:
1938
- PORT=$QUESTION_SVC_PORT
2039
- DB_URI=$QUESTION_SVC_DB_URI
2140
- FRONTEND_PORT=$FRONTEND_PORT
22-
ports:
23-
- $QUESTION_SVC_PORT:$QUESTION_SVC_PORT
24-
networks:
25-
- hidden
41+
expose:
42+
- $QUESTION_SVC_PORT
2643

2744
user-service:
2845
build:
@@ -33,10 +50,8 @@ services:
3350
- JWT_SECRET=$JWT_SECRET
3451
- EMAIL_ADDRESS=$EMAIL_ADDRESS
3552
- EMAIL_PASSWORD=$EMAIL_PASSWORD
36-
ports:
37-
- $USER_SVC_PORT:$USER_SVC_PORT
38-
networks:
39-
- hidden
53+
expose:
54+
- $USER_SVC_PORT
4055

4156
matching-service:
4257
build:
@@ -47,46 +62,18 @@ services:
4762
- REDIS_PORT=$REDIS_PORT
4863
- QUESTION_SVC_PORT=$QUESTION_SVC_PORT
4964
- COLLAB_SVC_PORT=$COLLAB_SVC_PORT
50-
ports:
51-
- $MATCHING_SVC_PORT:$MATCHING_SVC_PORT
65+
expose:
66+
- $MATCHING_SVC_PORT
5267
depends_on:
5368
- redis
5469
- question-service
5570
- collab-service
56-
networks:
57-
- hidden
58-
59-
api-gateway:
60-
image: nginx:1.26
61-
volumes:
62-
- ./api-gateway/templates:/etc/nginx/templates
63-
- ./api-gateway/nginx.conf:/etc/nginx/nginx.conf
64-
ports:
65-
- $API_GATEWAY_PORT:$API_GATEWAY_PORT
66-
environment:
67-
- PORT=$API_GATEWAY_PORT
68-
- FRONTEND_PORT=$FRONTEND_PORT
69-
- USER_SVC_PORT=$USER_SVC_PORT
70-
- QUESTION_SVC_PORT=$QUESTION_SVC_PORT
71-
- MATCHING_SVC_PORT=$MATCHING_SVC_PORT
72-
- COLLAB_SVC_PORT=$COLLAB_SVC_PORT
73-
depends_on:
74-
- frontend
75-
- user-service
76-
- question-service
77-
- matching-service
78-
- collab-service
79-
networks:
80-
- gateway
81-
- hidden
8271

8372
redis:
8473
image: redis:7.4-alpine
8574
restart: always
86-
ports:
87-
- $REDIS_PORT:$REDIS_PORT
88-
networks:
89-
- hidden
75+
expose:
76+
- $REDIS_PORT
9077

9178
collab-service:
9279
build:
@@ -95,13 +82,5 @@ services:
9582
- PORT=$COLLAB_SVC_PORT
9683
- DB_URI=$COLLAB_SVC_DB_URI
9784
- OPENAI_API_KEY=$OPENAI_API_KEY
98-
ports:
99-
- $COLLAB_SVC_PORT:$COLLAB_SVC_PORT
100-
networks:
101-
- hidden
102-
103-
networks:
104-
gateway:
105-
106-
hidden:
107-
internal: true
85+
expose:
86+
- $COLLAB_SVC_PORT

frontend/components/collab/question-display.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { Badge } from "@/components/ui/badge";
1212
import LoadingScreen from "@/components/common/loading-screen";
1313
import { getQuestion } from "@/lib/api/question-service/get-question";
14+
import { useToast } from "@/components/hooks/use-toast";
1415
import { useAuth } from "@/app/auth/auth-context";
1516
import { getQuestionId } from "@/lib/api/collab-service/get-questionId";
1617

@@ -37,15 +38,26 @@ export default function QuestionDisplay({
3738
date?: Date;
3839
}) {
3940
const auth = useAuth();
41+
const { toast } = useToast();
4042
const token = auth?.token;
4143
const [question, setQuestion] = useState<Question | null>(null);
4244
const [loading, setLoading] = useState(true);
4345

4446
useEffect(() => {
4547
async function fetchQuestion() {
4648
try {
49+
console.log(auth);
50+
if (!auth || !auth.token) {
51+
toast({
52+
title: "Access denied",
53+
description: "No authentication token found",
54+
variant: "destructive",
55+
});
56+
return;
57+
}
58+
4759
// Call to the collab microservice to get questionId by roomId
48-
const response = await getQuestionId(roomId);
60+
const response = await getQuestionId(auth.token, roomId);
4961
const data = await response.json();
5062

5163
if (data.questionId) {

frontend/lib/api/collab-service/get-questionId.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { AuthType, collabServiceUri } from "@/lib/api/api-uri";
22

3-
export const getQuestionId = async (roomId: string) => {
3+
export const getQuestionId = async (jwtToken: string, roomId: string) => {
44
const response = await fetch(
5-
`${collabServiceUri(window.location.hostname, AuthType.Public)}/collab/rooms/${roomId}/questionId`,
5+
`${collabServiceUri(window.location.hostname, AuthType.Private)}/collab/rooms/${roomId}/questionId`,
66
{
77
method: "GET",
88
headers: {
9+
Authorization: `Bearer ${jwtToken}`,
910
"Content-Type": "application/json",
1011
},
1112
}

0 commit comments

Comments
 (0)