Skip to content

Commit 27390ba

Browse files
authored
Merge pull request #74 from Eclipse-Dominator/link_execution_w_submission
Link execution w submission
2 parents f2a8240 + 9c1f030 commit 27390ba

28 files changed

+580
-424
lines changed

api_gateway/src/proxy/service_addresses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export const questionServiceUrl = isLocal ? "http://localhost:8080" : "http://qu
55
export const userServiceHostUrl = isLocal ? "http://localhost:8081" : "http://user-service:8081/";
66
export const matchServiceHostUrl = isLocal ? "http://localhost:8082" : "http://matching-service:8082"
77
export const collabServiceHostUrl = isLocal ? "http://localhost:8083" : "http://collab-service:8083"
8-
export const executionServiceHostUrl = isLocal ? "http://localhost:8090" : "http://code-execution:8090";
8+
export const executionServiceHostUrl = isLocal ? "http://localhost:8090" : "http://code-execution:8090/";

code_execution/src/executor_client.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import axios from "axios";
22
import { createBatchSubmission, getQnStdInOut } from "./testcases";
33
import { callbacks, langToId } from "./shared";
44
import { judge0Result, judge0submission, submissionResult } from "./types";
5+
import { submitSubmission } from "./submission_client";
56

6-
const JUDGE_API_URL = "https://judge0-ce.p.rapidapi.com"; //"http://judge0-server:2358/submissions";
7+
const JUDGE_API_URL = "http://peerprep-g10.com:2358"; //"https://judge0-ce.p.rapidapi.com";
78
const API_KEY = process.env.JUDGE0_API_KEY;
89

910
async function submitIndividual(submission: judge0submission) {
@@ -13,7 +14,6 @@ async function submitIndividual(submission: judge0submission) {
1314
{
1415
headers: {
1516
"Content-Type": "application/json",
16-
"X-Rapidapi-Key": API_KEY,
1717
},
1818
params: { base64_encoded: "true" },
1919
}
@@ -29,7 +29,6 @@ async function submitCode(submission: judge0submission[]) {
2929
{
3030
headers: {
3131
"Content-Type": "application/json",
32-
"X-Rapidapi-Key": API_KEY,
3332
},
3433
params: { base64_encoded: "true" },
3534
}
@@ -52,9 +51,6 @@ function pollIndividualTillComplete(
5251
) {
5352
setTimeout(() => {
5453
const options = {
55-
headers: {
56-
"X-Rapidapi-Key": API_KEY,
57-
},
5854
params: {
5955
fields: "status",
6056
},
@@ -114,7 +110,6 @@ async function delSubmissions(tokens: string[]) {
114110
params: { fields: "status_id" },
115111
headers: {
116112
"X-Judge0-User": "Auth-Judge0-User",
117-
"X-Rapidapi-Key": API_KEY,
118113
},
119114
})
120115
)
@@ -155,8 +150,9 @@ export async function runSubmission(
155150
lang: string,
156151
qn__id: string,
157152
source_code: string,
158-
userid: string
153+
userid: number
159154
) {
155+
const submissionTime = new Date();
160156
const resDat: submissionResult = {
161157
completed: false,
162158
evaluated: 0,
@@ -190,4 +186,6 @@ export async function runSubmission(
190186

191187
resDat.verdict = resDat.verdict === "Unknown" ? "Accepted" : resDat.verdict;
192188
resDat.completed = true;
193-
}
189+
190+
submitSubmission(resDat.verdict, lang, qn__id, userid, source_code, submissionTime); // runs in the bg
191+
}

code_execution/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ app.get("/api/code/result/:token", async (req, res) => {
3838
return res.status(400).json({ error: "id not found" });
3939
}
4040

41-
res.json(response);
41+
res.status(200).json(response);
4242
} catch (error) {
4343
console.error(error);
4444
res.status(500).json({ error: "An error occurred" });

code_execution/src/shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export const callbacks: callbackMapping = {};
44

55
export const langToId: { [key: string]: number } = {
66
"c++17": 76,
7-
"python3": 92,
8-
"java": 91,
9-
}
7+
python3: 71,
8+
java: 62,
9+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import axios from "axios";
2+
import { judge0Result, submissionResult } from "./types";
3+
4+
type Question = {
5+
id: number;
6+
_id: string;
7+
title: string;
8+
description: string;
9+
topics: string[];
10+
difficulty: number;
11+
};
12+
13+
const fetchQn = async (id: string) => {
14+
const response = await axios.get<Question>(
15+
`http://question-service:8080/api/questions/${id}`
16+
);
17+
return response.data;
18+
};
19+
20+
export const submitSubmission = async (
21+
verdict: string,
22+
language: string,
23+
qid: string,
24+
userId: number,
25+
sourceCode: string,
26+
time: Date
27+
) => {
28+
const question = await fetchQn(qid);
29+
const submission = {
30+
question__id: question._id,
31+
userId: userId,
32+
questionTitle: question.title,
33+
questionId: question.id,
34+
difficulty: question.difficulty,
35+
topics: question.topics,
36+
verdict: verdict,
37+
sourceCode: sourceCode,
38+
language: language,
39+
answeredAt: time.toISOString(),
40+
};
41+
await axios.post(
42+
`http://user-service:8081/api/users/${userId}/addquestions`,
43+
submission
44+
);
45+
};

frontend/src/api/code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function submitCodeForExecution(data_payload: any) {
77
}
88

99
export async function getExecutionResult(token : string) {
10-
const res = await apiGatewayClient.post(`/api/code/result/${token}`);
10+
const res = await apiGatewayClient.get(`/api/code/result/${token}`);
1111

1212
return res;
1313
}

frontend/src/api/user.ts

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { apiGatewayClient } from "./gateway";
88
* @returns An array of completed questions.
99
*/
1010
export async function fetchUserCompletedQuestions(
11-
userId: String
12-
): Promise<SolvedQuestion[]> {
11+
userId: number
12+
): Promise<SolvedQuestion[]> {
1313
try {
1414
const response: AxiosResponse = await apiGatewayClient.get(
1515
`/api/users/${userId}/questions`
@@ -19,14 +19,16 @@ export async function fetchUserCompletedQuestions(
1919
const completedQuestions: SolvedQuestion[] = resData.map(
2020
(q: any) =>
2121
new SolvedQuestion(
22-
q._id,
23-
q.id,
24-
q.title,
25-
q.description,
22+
q.question__id,
23+
q.questionId,
24+
q.questionTitle,
25+
"", // not impt
2626
q.topics,
2727
q.difficulty,
28-
false, // Default value for solved
29-
undefined // Default value for solvedDate
28+
q.verdict,
29+
q.sourceCode,
30+
q.language,
31+
q.answeredAt // Default value for solvedDate
3032
)
3133
);
3234

@@ -38,50 +40,52 @@ export async function fetchUserCompletedQuestions(
3840
}
3941
}
4042

41-
/**
42-
* Add a new question to the user's completed questions.
43-
* @param userId - The ID of the user to whom you want to add the question.
44-
* @param questionId - The ID of the question you want to add.
45-
* @param complexity - The complexity of the question.
46-
* @param category - The category of the question.
47-
* @returns The added question.
48-
*/
49-
export async function addUserQuestion(
50-
userId: number,
51-
questionId: string,
52-
complexity: number,
53-
category: string[]
54-
): Promise<SolvedQuestion> {
55-
try {
56-
const response: AxiosResponse = await apiGatewayClient.post(
57-
`/api/users/${userId}/addquestions`,
58-
{
59-
userId,
60-
questionId,
61-
complexity,
62-
category,
63-
}
64-
);
43+
// /**
44+
// * Add a new question to the user's completed questions.
45+
// * @param userId - The ID of the user to whom you want to add the question.
46+
// * @param questionId - The ID of the question you want to add.
47+
// * @param complexity - The complexity of the question.
48+
// * @param category - The category of the question.
49+
// * @returns The added question.
50+
// */
51+
// export async function addUserQuestion(
52+
// userId: number,
53+
// questionId: string,
54+
// complexity: number,
55+
// category: string[]
56+
// ): Promise<SolvedQuestion> {
57+
// try {
58+
// const response: AxiosResponse = await apiGatewayClient.post(
59+
// `/api/users/${userId}/addquestions`,
60+
// {
61+
// userId,
62+
// questionId,
63+
// complexity,
64+
// category,
65+
// }
66+
// );
6567

66-
const resData = response.data;
67-
const addedQuestion: SolvedQuestion = new SolvedQuestion(
68-
resData._id,
69-
resData.id,
70-
resData.title,
71-
resData.description,
72-
resData.topics,
73-
resData.difficulty,
74-
false, // Default value for solved
75-
undefined // Default value for solvedDate
76-
);
68+
// const resData = response.data;
69+
// const addedQuestion: SolvedQuestion = new SolvedQuestion(
70+
// resData._id,
71+
// resData.id,
72+
// resData.title,
73+
// resData.description,
74+
// resData.topics,
75+
// resData.difficulty,
76+
// resData.verdict,
77+
// resData.sourceCode,
78+
// resData.language,
79+
// undefined // Default value for solvedDate
80+
// );
7781

78-
return addedQuestion;
79-
} catch (error) {
80-
// Handle errors appropriately, e.g., log the error or throw it to be handled by the caller.
81-
console.error(error);
82-
throw error;
83-
}
84-
}
82+
// return addedQuestion;
83+
// } catch (error) {
84+
// // Handle errors appropriately, e.g., log the error or throw it to be handled by the caller.
85+
// console.error(error);
86+
// throw error;
87+
// }
88+
// }
8589

8690

8791
/**

frontend/src/components/MatchMakeBtn/MatchMakeBtn.component.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ import { useMatchmake } from "../../contexts/matchmake.context";
1616
import { AiOutlineDisconnect as DisconnectIcon } from "react-icons/ai";
1717
import { useSelector } from "react-redux";
1818
import { selectUser } from "../../reducers/authSlice";
19-
20-
const diffRange = [
21-
[0, 2.9],
22-
[3, 5.9],
23-
[6, 7.9],
24-
[8, 9.9],
25-
[0, 9.9],
26-
];
19+
import { diffRanges } from "../../helper/DifficultyFilterHelper";
2720

2821
const MatchMakeBtn = () => {
2922
const user = useSelector(selectUser);
@@ -79,21 +72,14 @@ const MatchMakeBtn = () => {
7972
)}
8073

8174
<MenuList>
82-
<MenuItem onClick={() => findMatch(diffRange[0][0], diffRange[0][1])}>
83-
Basic
84-
</MenuItem>
85-
<MenuItem onClick={() => findMatch(diffRange[1][0], diffRange[1][1])}>
86-
Simple
87-
</MenuItem>
88-
<MenuItem onClick={() => findMatch(diffRange[2][0], diffRange[2][1])}>
89-
Medium
90-
</MenuItem>
91-
<MenuItem onClick={() => findMatch(diffRange[3][0], diffRange[3][1])}>
92-
Hard
93-
</MenuItem>
94-
<MenuItem onClick={() => findMatch(diffRange[4][0], diffRange[4][1])}>
95-
All
96-
</MenuItem>
75+
{diffRanges.map((dr) => (
76+
<MenuItem
77+
onClick={() => findMatch(dr.range[0], dr.range[1])}
78+
id={dr.difficulty}
79+
>
80+
{dr.difficulty}
81+
</MenuItem>
82+
))}
9783
</MenuList>
9884
</Menu>
9985
);

0 commit comments

Comments
 (0)