Skip to content

Commit ffd1f5a

Browse files
authored
Merge pull request #4 from CODESPACE-CE-PROJECT/CE-008-Compiler
Ce 008 compiler
2 parents 7f502a2 + f1a8924 commit ffd1f5a

21 files changed

+650
-833
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ node_modules/
66
.gitignore
77
dist/
88
logs/
9-
ear
109
.env.example
1110
.github

.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
PORT=
2-
DOCKER_HOST=
2+
RMQUSER=
3+
RMQPASS=
4+
RMQHOST=
5+
REDISHOST=
6+
BACKEND_URL=
7+
JWT_SECRET=

.github/workflows/deployment.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@ jobs:
2828
uses: actions/checkout@v3
2929
- name: Set Environment Variables 🔠
3030
env:
31-
PORT: ${{ secrets.PORT }}
3231
RMQUSER: ${{ secrets.RMQUSER }}
3332
RMQPASS: ${{ secrets.RMQPASS }}
3433
RMQHOST: ${{ secrets.RMQHOST }}
35-
RMQNAME: ${{ secrets.RMQNAME }}
34+
REDISHOST: ${{ secrets.REDISHOST }}
3635
BACKEND_URL: ${{ secrets.BACKEND_URL }}
3736
JWT_SECRET: ${{ secrets.JWT_SECRET }}
3837
run: |
39-
echo "PORT=$PORT" >> .env
4038
echo "JWT_SECRET=$JWT_SECRET" >> .env
4139
echo "RMQUSER=$RMQUSER" >> .env
4240
echo "RMQPASS=$RMQPASS" >> .env
4341
echo "RMQHOST=$RMQHOST" >> .env
4442
echo "RMQNAME=$RMQNAME" >> .env
43+
echo "REDISHOST=$REDISHOST" >> .env
4544
echo "BACKEND_URL=$BACKEND_URL" >> .env
4645
4746
- name: Clear Cache 🫧

docker-compose.prod.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ services:
66
container_name: compiler
77
build:
88
context: .
9-
dockerfile: Dockerfile
9+
dockerfile: Dockerfile
10+
privileged: true
1011
environment:
11-
PORT: ${PORT}
12+
PORT: 3003
1213
RMQUSER: ${RMQUSER}
1314
RMQPASS: ${RMQPASS}
1415
RMQHOST: ${RMQHOST}
15-
RMQNAME: ${RMQNAME}
16+
REDISHOST: ${REDISHOST}
1617
BACKEND_URL: ${BACKEND_URL}
1718
JWT_SECRET: ${JWT_SECRET}
1819
restart: unless-stopped

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,7 @@
1212
"author": "UnixVextor <withun.wch@gmail.com>",
1313
"license": "MIT",
1414
"dependencies": {
15-
"@types/amqplib": "^0.10.5",
16-
"@types/axios": "^0.14.0",
17-
"@types/cors": "^2.8.17",
18-
"@types/dockerode": "^3.3.26",
19-
"@types/express": "^4.17.21",
20-
"@types/jsonwebtoken": "^9.0.7",
21-
"@types/pino": "^7.0.5",
22-
"@types/strip-comments": "^2.0.4",
23-
"@types/swagger-jsdoc": "^6.0.4",
24-
"@types/swagger-ui-express": "^4.1.6",
25-
"@types/tar-stream": "^3.1.3",
26-
"@types/tress": "^1.0.5",
27-
"amqplib": "^0.10.4",
15+
"amqplib": "^0.10.4",
2816
"axios": "^1.7.7",
2917
"cors": "^2.8.5",
3018
"dayjs": "^1.11.13",
@@ -36,14 +24,26 @@
3624
"lexical-parser": "^1.0.0",
3725
"pino": "^9.4.0",
3826
"pino-pretty": "^11.2.2",
27+
"redis": "^4.7.0",
3928
"rimraf": "^5.0.5",
4029
"strip-comments": "^2.0.1",
41-
"swagger-jsdoc": "^6.2.8",
42-
"swagger-ui-express": "^5.0.1",
4330
"tar-stream": "^3.1.7",
4431
"tress": "^1.1.4",
4532
"tsx": "^4.7.0",
4633
"typescript": "^5.3.3",
4734
"zod": "^3.22.4"
35+
},
36+
"devDependencies": {
37+
"@types/redis": "^4.0.11",
38+
"@types/amqplib": "^0.10.5",
39+
"@types/axios": "^0.14.0",
40+
"@types/cors": "^2.8.17",
41+
"@types/dockerode": "^3.3.26",
42+
"@types/express": "^4.17.21",
43+
"@types/jsonwebtoken": "^9.0.7",
44+
"@types/pino": "^7.0.5",
45+
"@types/strip-comments": "^2.0.4",
46+
"@types/tar-stream": "^3.1.3",
47+
"@types/tress": "^1.0.5"
4848
}
4949
}

src/controllers/compiler.controller.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ISubmissionRequest } from "../interfaces/submission.interface";
33
import { ICompileRequest } from "../interfaces/compiler.interface";
44
import { rabbitMQService } from "../services/rabbitmq.service";
55
import { RequestWithUser } from "../interfaces/auth.interface";
6+
import { redisClient } from "../services/redis.service";
67

78
export const compilerController = {
89
addSubmissionToRabbitMQ: async (req: Request, res: Response) => {
@@ -13,7 +14,11 @@ export const compilerController = {
1314
});
1415
}
1516
submission.token = (req as RequestWithUser).user.token;
17+
submission.username = (req as RequestWithUser).user.username
1618
await rabbitMQService.sendDataToQueue("submission", submission);
19+
20+
redisClient.set(`submissionState-${submission.username}`, "true", { EX: 240 })
21+
1722
return res.status(200).json({
1823
message: "Add To Queue Successfully",
1924
});
@@ -25,7 +30,7 @@ export const compilerController = {
2530
message: "Missing Required Fields",
2631
});
2732
}
28-
data.token = (req as RequestWithUser).user.token;
33+
data.username = (req as RequestWithUser).user.username;
2934
await rabbitMQService.sendDataToQueue("compiler", data);
3035
return res.status(200).json({
3136
message: "Add To Queue Successfully",

src/interfaces/compiler.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ICompileRequest {
1515
language: languageType;
1616
fileName: string;
1717
input: string;
18-
token?: string;
18+
username?: string;
1919
}
2020

2121
export interface IMoveFile {

src/interfaces/submission.interface.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface ISubmissionRequest {
66
language: languageType;
77
fileName: string;
88
token?: string;
9+
username?: string
910
}
1011

1112
export interface IResultProblem {
@@ -20,5 +21,23 @@ export interface ISubmission {
2021
output: string;
2122
isPass: boolean;
2223
}[];
23-
status: boolean;
24+
stateSubmission: string;
2425
}
26+
27+
export interface IResultSubmission {
28+
message: string;
29+
data: {
30+
submissionId: string;
31+
problemId: string;
32+
username: string;
33+
sourceCode: string;
34+
no: number;
35+
results: {
36+
output: string;
37+
isPass: boolean;
38+
}[];
39+
stateSubmission: boolean;
40+
createAt: Date;
41+
}
42+
}
43+
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
export interface ITestCase {
22
message: string;
33
data: {
4-
input: string;
5-
output: string;
6-
isHidden: boolean;
7-
}[];
4+
testCases: {
5+
testCaseId: string,
6+
input: string;
7+
output: string;
8+
isHidden: boolean;
9+
}[],
10+
constraint: {
11+
constraintId: string,
12+
type: ConstraintType,
13+
keyword: string,
14+
qunatities: number,
15+
problemId: string
16+
}[]
17+
};
18+
}
19+
20+
export enum ConstraintType {
21+
FUNCTION = "FUNCTION",
22+
METHOD = "METHOD",
823
}

src/interfaces/user.interface.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
export interface IUser {
2-
username: string;
3-
email: string;
4-
hashedPassword: string;
5-
studentNo: string;
6-
firstName: string;
7-
lastName: string;
8-
gender: string;
9-
role: string;
10-
picture: string;
11-
containerID: string;
12-
IpAddress: string;
13-
isActived: boolean;
14-
createdAt: Date;
15-
updatedAt: Date;
16-
schoolId: string;
17-
school: {
2+
message: string
3+
data: {
4+
username: string;
5+
email: string;
6+
hashedPassword: string;
7+
studentNo: string;
8+
firstName: string;
9+
lastName: string;
10+
gender: string;
11+
role: string;
12+
picture: string;
13+
containerID: string;
14+
IpAddress: string;
15+
isActived: boolean;
16+
createdAt: Date;
17+
updatedAt: Date;
1818
schoolId: string;
19-
schoolName: string;
20-
};
21-
token?: string;
19+
school: {
20+
schoolId: string;
21+
schoolName: string;
22+
};
23+
token?: string;
24+
}
2225
}

0 commit comments

Comments
 (0)