Skip to content

Commit 2ea2620

Browse files
committed
Add question history detail page
1 parent c4b57f0 commit 2ea2620

File tree

13 files changed

+288
-61
lines changed

13 files changed

+288
-61
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
matching-service,
4141
collab-service,
4242
code-execution-service,
43+
qn-history-service,
4344
]
4445
steps:
4546
- name: Checkout code

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ docker-compose down
3131
- Matching Service: http://localhost:3002
3232
- Collab Service: http://localhost:3003
3333
- Code Execution Service: http://localhost:3004
34+
- Question History Service: http://localhost:3005
3435
- Frontend: http://localhost:5173

backend/matching-service/src/handlers/websocketHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const handleWebsocketMatchEvents = (socket: Socket) => {
130130
return;
131131
}
132132

133-
const { complexity, category } = match;
133+
const { complexity, category, language } = match;
134134
questionService
135135
.get("/random", { params: { complexity, category } })
136136
.then((res) => {
@@ -143,6 +143,7 @@ export const handleWebsocketMatchEvents = (socket: Socket) => {
143143
submissionStatus: "Attempted",
144144
dateAttempted: new Date(),
145145
timeTaken: 0,
146+
language: language,
146147
})
147148
.then((res) => {
148149
io.to(matchId).emit(

backend/qn-history-service/.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ ORIGINS=http://localhost:5173,http://127.0.0.1:5173
66
# if using cloud MongoDB, replace with actual URI (run service separately)
77
MONGO_CLOUD_URI=<MONGO_CLOUD_URI>
88

9+
MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/
10+
911
# if using local MongoDB (run service with docker-compose)
1012
## MongoDB credentials
1113
MONGO_INITDB_ROOT_USERNAME=root

backend/qn-history-service/src/controllers/questionHistoryController.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ export const createQnHistory = async (
2424
submissionStatus,
2525
dateAttempted,
2626
timeTaken,
27+
language,
2728
} = req.body;
28-
console.log(
29-
userIds,
30-
questionId,
31-
title,
32-
submissionStatus,
33-
dateAttempted,
34-
timeTaken
35-
);
3629

3730
const newQnHistory = new QnHistory({
3831
userIds,
@@ -41,6 +34,7 @@ export const createQnHistory = async (
4134
submissionStatus,
4235
dateAttempted,
4336
timeTaken,
37+
language,
4438
});
4539

4640
await newQnHistory.save();
@@ -191,5 +185,6 @@ const formatQnHistoryResponse = (qnHistory: IQnHistory) => {
191185
dateAttempted: qnHistory.dateAttempted,
192186
timeTaken: qnHistory.timeTaken,
193187
code: qnHistory.code,
188+
language: qnHistory.language,
194189
};
195190
};

backend/qn-history-service/src/models/QnHistory.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface IQnHistory extends Document {
88
dateAttempted: Date;
99
timeTaken: Number;
1010
code: string;
11+
language: string;
1112
createdAt: Date;
1213
updatedAt: Date;
1314
}
@@ -25,6 +26,11 @@ const qnHistorySchema: Schema<IQnHistory> = new mongoose.Schema(
2526
dateAttempted: { type: Date, required: true },
2627
timeTaken: { type: Number, required: true },
2728
code: { type: String, required: false, default: "" },
29+
language: {
30+
type: String,
31+
enum: ["Python", "Java", "C"],
32+
required: true,
33+
},
2834
},
2935
{ timestamps: true }
3036
);

backend/qn-history-service/swagger.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ components:
3232
code:
3333
type: string
3434
description: Code submitted
35+
language:
36+
type: string
37+
description: Programming language used
3538

3639
definitions:
3740
QnHistory:
@@ -64,6 +67,9 @@ definitions:
6467
code:
6568
type: string
6669
description: Code submitted
70+
language:
71+
type: string
72+
description: Programming language used
6773
createdAt:
6874
type: string
6975
description: Date of creation

docker-compose-test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ services:
9898
restart: on-failure
9999
command: ["npm", "test"]
100100

101+
test-qn-history-service:
102+
image: peerprep/qn-history-service
103+
build: ./backend/qn-history-service
104+
environment:
105+
- NODE_ENV=test
106+
- SERVICE_PORT=3005
107+
- MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/
108+
depends_on:
109+
- test-mongo
110+
networks:
111+
- peerprep-network
112+
volumes:
113+
- ./backend/qn-history-service:/qn-history-service
114+
- /qn-history-service/node_modules
115+
restart: on-failure
116+
command: ["npm", "test"]
117+
101118
test-frontend:
102119
image: peerprep/frontend
103120
build: ./frontend

frontend/src/App.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import MatchProvider from "./contexts/MatchContext";
2424
import CollabSandbox from "./pages/CollabSandbox";
2525
import NoDirectAccessRoutes from "./components/NoDirectAccessRoutes";
2626
import EmailVerification from "./pages/EmailVerification";
27+
import QuestionHistoryDetail from "./pages/QuestionHistoryDetail";
2728

2829
function App() {
2930
return (
@@ -51,6 +52,14 @@ function App() {
5152
</ProfileContextProvider>
5253
}
5354
/>
55+
<Route
56+
path="profile/:userId/:qnHistoryId"
57+
element={
58+
<AuthProvider>
59+
<QuestionHistoryDetail />
60+
</AuthProvider>
61+
}
62+
/>
5463
<Route path="matching" element={<ProtectedRoutes />}>
5564
<Route element={<NoDirectAccessRoutes />}>
5665
<Route index element={<Matching />} />

frontend/src/components/ServerError/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ServerError: React.FC<ServerErrorProps> = (props) => {
99

1010
return (
1111
<AppMargin classname={`${classes.fullheight} ${classes.center}`}>
12-
<Box>
12+
<Box sx={(theme) => ({marginTop: theme.spacing(4) })}>
1313
<Typography
1414
component={"h1"}
1515
variant="h3"

0 commit comments

Comments
 (0)