Skip to content

Commit 9f3184e

Browse files
committed
2 parents 1f5783e + e77ad2e commit 9f3184e

File tree

4 files changed

+329
-3
lines changed

4 files changed

+329
-3
lines changed

Frontend/src/components/Sidebar.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ function Sidebar() {
5656

5757
fetchUser();
5858

59+
// Custom event listener for category updates
60+
const handleCategoryChange = () => {
61+
fetchCategories();
62+
};
63+
window.addEventListener("categoryChange", handleCategoryChange);
64+
65+
5966
console.log("categories: ", categories)
6067

6168
const matchingServiceHost = '34.126.114.137' || 'localhost';
@@ -87,6 +94,7 @@ function Sidebar() {
8794

8895
return () => {
8996
websocket.close();
97+
window.removeEventListener("categoryChange", handleCategoryChange);
9098
};
9199
}, []);
92100

Frontend/src/components/question/EditQn.jsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ function EditQn({ question, handleClose, editQuestion }) {
6161
console.log(`newCategories are ${newCategories}`);
6262

6363
categoryService.createCategories(newCategories)
64-
.then(result => console.log(result.data))
64+
.then(result => {
65+
console.log(result.data)
66+
window.dispatchEvent(new Event("categoryChange"));
67+
})
6568
.catch(e => {
6669
if (e.response && e.response.status === 400) {
6770
setError(e.response.data.error);
@@ -71,7 +74,26 @@ function EditQn({ question, handleClose, editQuestion }) {
7174

7275
questionService.updateQuestion(question._id, updatedQuestion)
7376
.then(result => {
74-
77+
const initialCategories = question.category;
78+
const categoriesRemoved = initialCategories.filter(item => !categories.includes(item));
79+
80+
// check each category to see if it should be deleted
81+
categoriesRemoved.forEach(async (category) => {
82+
try {
83+
const remainingQuestions = await questionService.getQuestionsByCategory(category);
84+
85+
// if no other questions have this category, delete the category
86+
if (remainingQuestions.length === 0) {
87+
await categoryService.deleteCategory(category);
88+
console.log(`Category ${category} deleted.`);
89+
// dispatch the event here
90+
window.dispatchEvent(new Event("categoryChange"));
91+
}
92+
} catch (err) {
93+
console.error(`Error processing category ${category}:`, err);
94+
}
95+
});
96+
7597
editQuestion(question._id, updatedQuestion);
7698
console.log('Question edited successfully:', result)
7799
handleClose();

Frontend/src/components/question/Question.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function Question() {
2929
.then(result => {
3030
setQuestions(result.data);
3131
})
32+
3233
.catch(err => console.log(err));
3334
}, []);
3435

@@ -199,7 +200,7 @@ function Question() {
199200
return (
200201
<div
201202
className="container-fluid ag-theme-quartz"
202-
style={{ height: 500 }}
203+
style={{ height: '80vh' }}
203204
>
204205
<AgGridReact
205206
rowData={questions}

yaml-of-yamls.yaml

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
# QUESTION SERVICE OK
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: question-deployment
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: question
10+
template:
11+
metadata:
12+
labels:
13+
app: question
14+
spec:
15+
containers:
16+
- name: question
17+
image: asia-southeast1-docker.pkg.dev/powerful-lore-423309-n1/cs3219/question-service:latest
18+
ports:
19+
- containerPort: 3001
20+
env:
21+
- name: DB_USERNAME
22+
value: "G04DemoUsername"
23+
- name: DB_PASSWORD
24+
value: "G04DemoPassword"
25+
26+
---
27+
28+
apiVersion: v1
29+
kind: Service
30+
metadata:
31+
name: question-service
32+
spec:
33+
type: NodePort
34+
selector:
35+
app: question
36+
ports:
37+
- port: 3001 #My wish
38+
targetPort: 3001
39+
40+
---
41+
42+
# USER SERVICE OK
43+
apiVersion: apps/v1
44+
kind: Deployment
45+
metadata:
46+
name: user-deployment
47+
spec:
48+
selector:
49+
matchLabels:
50+
app: user
51+
template:
52+
metadata:
53+
labels:
54+
app: user
55+
spec:
56+
containers:
57+
- name: user
58+
image: asia-southeast1-docker.pkg.dev/powerful-lore-423309-n1/cs3219/user-service:latest
59+
ports:
60+
- containerPort: 3002
61+
env:
62+
- name: ENV
63+
value: "PROD"
64+
- name: DB_CLOUD_URI
65+
value: "mongodb+srv://G04DemoUsername:[email protected]/User-DB?retryWrites=true&w=majority&appName=CS3219"
66+
- name: PORT
67+
value: "3002"
68+
- name: JWT_SECRET
69+
value: "cwztSBrxeqzSTXWnLMbKazZYmnS3BhfO0/GHKo3+7cMWV2CvSzKaG0NOJ1rtF/5pV3xLUpblGFCfbs/DZIx1Mbc9qv8SrW7U77rbZlPEefnhAyUBEJXIOxlM5NgsY0xkzYH+D60QJZlsMcDn6goq73lFWeiW3QgsGSxucXtuHaT4sGZ6i8y+WkfVaMz8pD2nUU1nW6lTDlLLEDA/1cUUodMHDcMNZ1XpiAQYXR0Kc4hyqkBUInZQDfsyh76PJ+TthOQihybrhO3FDtDX7/AXO2Cgutz8LRVO0mPCz8vn8GE8RpOphYO6AqF2NoncABcDK+Q0/CaZ+tUq3UY3J7oZgg=="
70+
71+
---
72+
73+
apiVersion: v1
74+
kind: Service
75+
metadata:
76+
name: user-service
77+
spec:
78+
type: NodePort
79+
selector:
80+
app: user
81+
ports:
82+
- port: 3002 #My wish
83+
targetPort: 3002
84+
85+
---
86+
87+
# # COLLAB SERVICE
88+
# apiVersion: apps/v1
89+
# kind: Deployment
90+
# metadata:
91+
# name: collab-deployment
92+
# spec:
93+
# selector:
94+
# matchLabels:
95+
# app: collab
96+
# template:
97+
# metadata:
98+
# labels:
99+
# app: collab
100+
# spec:
101+
# containers:
102+
# - name: collab
103+
# image: asia-southeast1-docker.pkg.dev/powerful-lore-423309-n1/cs3219/collab-service:latest
104+
# ports:
105+
# - containerPort: 3004
106+
107+
# ---
108+
109+
# apiVersion: v1
110+
# kind: Service
111+
# metadata:
112+
# name: collab-service
113+
# spec:
114+
# type: NodePort
115+
# selector:
116+
# app: collab
117+
# ports:
118+
# - port: 3004 #My wish
119+
# targetPort: 3004
120+
# - port: 1234
121+
# targetPort: 1234
122+
123+
# ---
124+
125+
# # MATCHING SERVICE
126+
# apiVersion: apps/v1
127+
# kind: Deployment
128+
# metadata:
129+
# name: matching-deployment
130+
# spec:
131+
# selector:
132+
# matchLabels:
133+
# app: matching
134+
# template:
135+
# metadata:
136+
# labels:
137+
# app: matching
138+
# spec:
139+
# containers:
140+
# - name: matching
141+
# image: asia-southeast1-docker.pkg.dev/powerful-lore-423309-n1/cs3219/matching-service:latest
142+
# ports:
143+
# - containerPort: 8080
144+
# env:
145+
# - name: PORT
146+
# value: "8080"
147+
# - name: RABBITMQ_URL
148+
# value: "amqps://ofolkusu:[email protected]/ofolkusu"
149+
150+
# ---
151+
152+
# apiVersion: v1
153+
# kind: Service
154+
# metadata:
155+
# name: matching-service
156+
# spec:
157+
# type: NodePort
158+
# selector:
159+
# app: matching
160+
# ports:
161+
# - port: 8080 #My wish
162+
# targetPort: 8080
163+
#
164+
# ---
165+
# HISTORY SERVICE
166+
apiVersion: apps/v1
167+
kind: Deployment
168+
metadata:
169+
name: history-deployment
170+
spec:
171+
selector:
172+
matchLabels:
173+
app: history
174+
template:
175+
metadata:
176+
labels:
177+
app: history
178+
spec:
179+
containers:
180+
- name: history
181+
image: asia-southeast1-docker.pkg.dev/powerful-lore-423309-n1/cs3219/history-service:latest
182+
ports:
183+
- containerPort: 3005
184+
env:
185+
- name: DB_USERNAME
186+
value: "G04DemoUsername"
187+
- name: DB_PASSWORD
188+
value: "G04DemoPassword"
189+
190+
---
191+
192+
apiVersion: v1
193+
kind: Service
194+
metadata:
195+
name: history-service
196+
spec:
197+
type: NodePort
198+
selector:
199+
app: history
200+
ports:
201+
- port: 3005 #My wish
202+
targetPort: 3005
203+
204+
---
205+
206+
# INGRESS
207+
apiVersion: networking.k8s.io/v1
208+
kind: Ingress
209+
metadata:
210+
name: peerprep-ingress
211+
annotations:
212+
kubernetes.io/ingress.class: "gce"
213+
kubernetes.io/ingress.global-static-ip-name: peerprep-ip
214+
spec:
215+
defaultBackend:
216+
service:
217+
name: question-service
218+
port:
219+
number: 3001
220+
rules:
221+
- http:
222+
paths:
223+
# Question Service
224+
- path: /api/categories
225+
pathType: Prefix
226+
backend:
227+
service:
228+
name: question-service
229+
port:
230+
number: 3001
231+
- path: /api/questions
232+
pathType: Prefix
233+
backend:
234+
service:
235+
name: question-service
236+
port:
237+
number: 3001
238+
# User Service
239+
- path: /auth
240+
pathType: Prefix
241+
backend:
242+
service:
243+
name: user-service
244+
port:
245+
number: 3002
246+
- path: /users
247+
pathType: Prefix
248+
backend:
249+
service:
250+
name: user-service
251+
port:
252+
number: 3002
253+
# History Service
254+
- path: /api/histories
255+
pathType: Prefix
256+
backend:
257+
service:
258+
name: history-service
259+
port:
260+
number: 3005
261+
262+
# apiVersion: apps/v1
263+
# kind: Deployment
264+
# metadata:
265+
# name: frontend-deployment
266+
# spec:
267+
# selector:
268+
# matchLabels:
269+
# app: frontend
270+
# template:
271+
# metadata:
272+
# labels:
273+
# app: frontend
274+
# spec:
275+
# containers:
276+
# - name: frontend
277+
# image: asia-southeast1-docker.pkg.dev/powerful-lore-423309-n1/cs3219/frontend:test2
278+
# ports:
279+
# - containerPort: 8080
280+
281+
# ---
282+
# apiVersion: v1
283+
# kind: Service
284+
# metadata:
285+
# name: frontend-service
286+
# spec:
287+
# type: NodePort
288+
# selector:
289+
# app: frontend
290+
# ports:
291+
# - protocol: TCP
292+
# port: 80 #My wish
293+
# targetPort: 8080
294+
295+
# ---

0 commit comments

Comments
 (0)