Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
361 commits
Select commit Hold shift + click to select a range
241b6d7
fix bson bug
oeggy03 Sep 29, 2024
640e23a
Fix bson bug again
oeggy03 Sep 29, 2024
4ec3e43
Initialise Docker
tjch-o Oct 5, 2024
d2ac9a7
Fix bcrypt not working on Docker issue
tjch-o Oct 5, 2024
b80b36c
Update name of network bridge
tjch-o Oct 5, 2024
41794c4
Update docker-compose.ymp to use named volumes to fix npm install iss…
oeggy03 Oct 6, 2024
96926db
Update README.md
tjch-o Oct 6, 2024
c462f6a
Merge pull request #24 from CS3219-AY2425S1/containerisation
wesho1107 Oct 6, 2024
6d8548c
Add logging to question service
tjch-o Oct 7, 2024
5901348
Modify backend of edit questions to fit new duplicate checks
tjch-o Oct 7, 2024
aa77f63
Initialise RabbitMQ messaging queue
tjch-o Oct 11, 2024
9b5c006
Remove unnecessary logs
tjch-o Oct 11, 2024
77729c5
Modify data type for message queue to receive messages
tjch-o Oct 12, 2024
0027065
Merge pull request #25 from CS3219-AY2425S1/question-service
lunaroddity Oct 12, 2024
ff849c8
Update package.json script
tjch-o Oct 12, 2024
d0c45c0
Merge branch 'main' into rabbitmq
tjch-o Oct 12, 2024
8a29429
Refactor code
tjch-o Oct 12, 2024
f179096
First attempt at matching algorithm
tjch-o Oct 13, 2024
105374e
Implement websockets for matching
tjch-o Oct 13, 2024
0878c5a
Pre-populate existing question data in Edit Form
lunaroddity Oct 13, 2024
67fc2a1
Switch to only use websockets
tjch-o Oct 14, 2024
cf5f7b2
Uninstall redundant dependencies
tjch-o Oct 14, 2024
f2b27d9
Fix edit difficulty bug
tjch-o Oct 14, 2024
c14d0f0
Fix edit form error message
lunaroddity Oct 14, 2024
7252ba4
Merge pull request #26 from CS3219-AY2425S1/PEERPREP-8-Edit-Questions…
tjch-o Oct 15, 2024
c7aa5f1
Submit only values of dirty fields for edit
lunaroddity Oct 15, 2024
bc1d487
Implement frontend for matching service form
wesho1107 Oct 15, 2024
a5f2204
Update package-json
wesho1107 Oct 15, 2024
451cd36
Fix categories not sending request even when edited bug
tjch-o Oct 15, 2024
7442d58
Simplify backend duplicate checks
tjch-o Oct 15, 2024
f9dac18
Merge branch 'PEERPREP-8-Edit-Questions-Frontend' of https://github.c…
lunaroddity Oct 16, 2024
a35cc7c
Add error message for duplicate error for edit question form
lunaroddity Oct 16, 2024
16b5c04
Remove unnecessary log
tjch-o Oct 16, 2024
52cc5d6
Clean up code
lunaroddity Oct 16, 2024
22ab272
Merge branch 'PEERPREP-8-Edit-Questions-Frontend' of https://github.c…
lunaroddity Oct 16, 2024
e6b0952
Update Dockerfile
tjch-o Oct 16, 2024
c811be7
Merge pull request #27 from CS3219-AY2425S1/PEERPREP-8-Edit-Questions…
tjch-o Oct 17, 2024
56911e6
Add spinner for queue button
wesho1107 Oct 18, 2024
5d11fc3
Add disabled multiselect while searching
wesho1107 Oct 18, 2024
4bf1be9
Componentalize QuestionTable to reuse
wesho1107 Oct 18, 2024
e7418ee
Docker can now start the matching service and rabbitMQ
oeggy03 Oct 18, 2024
38c62e1
Create SuccessMatchInfo dialog
wesho1107 Oct 18, 2024
d70cb21
Style SuccessMatchInfo
wesho1107 Oct 18, 2024
5f835de
Add progress component to dialog
wesho1107 Oct 18, 2024
d94ba76
Add test for matching service
oeggy03 Oct 18, 2024
e9f6304
Update tests
oeggy03 Oct 18, 2024
4ed078b
Fix RabbitMQ not running locally error
tjch-o Oct 18, 2024
eca3603
Fix bug where one user after successful match is still shown no suita…
tjch-o Oct 18, 2024
9682408
Update timer
ldinghan Oct 19, 2024
707cc67
Merge pull request #28 from CS3219-AY2425S1/branch-match-timer
wesho1107 Oct 19, 2024
72c131e
Update styling for Select and MultiSelect and remove filters
wesho1107 Oct 19, 2024
a7db36f
Add socket.io-cleint for integrating backend matching service
wesho1107 Oct 19, 2024
e6828bd
Remove redundant categories line
wesho1107 Oct 19, 2024
c33443c
Implement endpoint for getting random question
tjch-o Oct 19, 2024
207fb29
Modify backend to send randomised question with best match
tjch-o Oct 19, 2024
4032a15
Use useRef for socket
wesho1107 Oct 20, 2024
e0f227c
Merge pull request #30 from CS3219-AY2425S1/rabbitmq
wesho1107 Oct 20, 2024
6f25416
Fix select for difficulty
wesho1107 Oct 20, 2024
c1bda8f
Fix filters for matching difficulty and categories
wesho1107 Oct 20, 2024
28d391f
Add condition case for empty array categories
wesho1107 Oct 20, 2024
05731c5
Fix successful matches not sent to frontend bug
tjch-o Oct 20, 2024
b3be216
Remove unnecessary import
tjch-o Oct 20, 2024
af4862e
Remove unnecessary logs
tjch-o Oct 20, 2024
3abf9dc
Handle case where there is a match but no suitable questions
tjch-o Oct 20, 2024
386a3e9
Merge pull request #31 from CS3219-AY2425S1/matching-integration
wesho1107 Oct 20, 2024
1fb2aac
Include userName in matching algortihm
wesho1107 Oct 20, 2024
6b2072a
Add toast for matchmaking timeout
wesho1107 Oct 20, 2024
23ae587
Both cancel and timeout works
oeggy03 Oct 20, 2024
db5f54b
hello
oeggy03 Oct 20, 2024
d2ad7a9
Add logging of queue for D4
tjch-o Oct 20, 2024
3ead58b
Fix bug where cancelling, then rematching immediately would not reset…
oeggy03 Oct 20, 2024
c0dd0e2
it works
oeggy03 Oct 20, 2024
773a9c0
Change back to 5 minutes
oeggy03 Oct 20, 2024
e329321
Merge pull request #33 from CS3219-AY2425S1/cancel-match
oeggy03 Oct 20, 2024
be6d847
Merge pull request #29 from CS3219-AY2425S1/PEERPREP-19-MatchFrontend
oeggy03 Oct 20, 2024
ea7699d
Add flex-wrap into QuestionDialog
wesho1107 Oct 22, 2024
054c6e1
Initialise backend of collaboration service
tjch-o Oct 25, 2024
59fae39
Replace Socket.io with y-websockets
tjch-o Oct 26, 2024
6046755
Create model for submissions
tjch-o Oct 26, 2024
d7c9541
Add boilerplate code
tjch-o Oct 26, 2024
8e640fb
Add code editor component
ldinghan Oct 27, 2024
9fef9e9
Add chat area
ldinghan Oct 27, 2024
d7c7dd8
Update packages
tjch-o Oct 27, 2024
9ddec62
Add websocket event listeners
tjch-o Oct 27, 2024
7176c66
Implement rooms for code editor
tjch-o Oct 28, 2024
776cd1d
Change event listener implementation for accepting match
tjch-o Oct 28, 2024
946e00a
Preliminary logic for accepting a match (backend) has been implemented.
oeggy03 Oct 28, 2024
6094573
Add frontend responsiveness for waiting and accepting matches between…
oeggy03 Oct 28, 2024
41e8779
Add language in matching criteria
tjch-o Oct 28, 2024
aa7e9d6
Implement language dropdown on frontend
tjch-o Oct 28, 2024
aa65437
Remove unnecessary logging
tjch-o Oct 28, 2024
75efc7b
Send roomId from collab-service to frontend
tjch-o Oct 30, 2024
aaede30
Merge branch 'branch-collaborative-fe' of https://github.com/CS3219-A…
oeggy03 Oct 30, 2024
07c93b5
Set up docker support for collab service
oeggy03 Oct 30, 2024
c161e2c
Refactor and abstract out websocket and create room logic.
oeggy03 Oct 30, 2024
c44517d
Implement test cases for questions
tjch-o Oct 30, 2024
8e194b0
Initialise backend of code execution service
tjch-o Oct 30, 2024
6e16fe4
Add functionality for matched users to enter a common room
oeggy03 Oct 31, 2024
31b45e5
Add room validation checks to verify existence of room and authorizat…
oeggy03 Oct 31, 2024
41f859b
Fetch test cases from question microservice
tjch-o Oct 31, 2024
55e7575
Implement HTTP request to OneCompiler
tjch-o Oct 31, 2024
6a50ad5
temporary commit
oeggy03 Oct 31, 2024
5dce30e
Send code for execution
tjch-o Oct 31, 2024
a3b95e5
Implement successful code execution and comparison with test cases
tjch-o Oct 31, 2024
9250143
Add types
tjch-o Oct 31, 2024
8151cc7
Update add and edit forms to include test cases
ldinghan Nov 1, 2024
8bd1164
Make edit question form scrollable
tjch-o Nov 1, 2024
49156d1
Code editor collaboration backend + frontend syncs and works
oeggy03 Nov 1, 2024
7c5398b
Fix bug where initial code does not load in
oeggy03 Nov 1, 2024
52ca7f3
Remove submission from collaboration microservice
tjch-o Nov 1, 2024
652a5c5
Shift submission model to code execution microservice
tjch-o Nov 1, 2024
b596036
Add code submission endpoint
tjch-o Nov 1, 2024
5748dbf
Submit code into database
tjch-o Nov 1, 2024
e44268d
Refactor execution of code
tjch-o Nov 1, 2024
e9e2822
Refactor submission of code
tjch-o Nov 1, 2024
d82143f
Remove unnecessary files and packages
tjch-o Nov 1, 2024
905ac9e
Modify test cases implementation in frontend
tjch-o Nov 2, 2024
62bd7be
Update profile page include stats sidebar
wesho1107 Nov 2, 2024
1f56d36
Enable code editor to be in language chosen in match
tjch-o Nov 2, 2024
9624882
Add delete room controller
tjch-o Nov 2, 2024
6bf636c
Style difficulty boxes for problems solved
wesho1107 Nov 2, 2024
2246ea0
Add states for profile page
wesho1107 Nov 2, 2024
6686753
Modify backend to use matchId
tjch-o Nov 2, 2024
e82458a
Add HistoryTable
wesho1107 Nov 2, 2024
384cb45
Add multipurpose dropdown for navbar
wesho1107 Nov 2, 2024
b42cc56
Change into cursor pointer
wesho1107 Nov 2, 2024
bb4c6ff
Standardize shadow and hover stylings
wesho1107 Nov 2, 2024
333b63a
Update fontsize
wesho1107 Nov 2, 2024
94c04c1
Implement adding successful matches
tjch-o Nov 2, 2024
e5564b1
Shift controller to matching service
tjch-o Nov 2, 2024
b57dfbf
Update directory
tjch-o Nov 2, 2024
9b45647
Update submission schema
tjch-o Nov 2, 2024
330d419
Add logic to update matches database
tjch-o Nov 3, 2024
0f98bc7
Update Dockerfile
tjch-o Nov 4, 2024
bb8ef51
Add ground breaking bug fix
oeggy03 Nov 5, 2024
eb804f3
Update chat name and hide room id
ldinghan Nov 5, 2024
56e5f76
Merge branch 'code-execution-backend' into working-collab-service
tjch-o Nov 5, 2024
f914ae1
Format codeeditor page
ldinghan Nov 5, 2024
1615afb
Initialise matching database and refactor code
tjch-o Nov 5, 2024
f98ad16
Implement adding to matching database
tjch-o Nov 5, 2024
037305b
Add exit, run, submit buttons in code editor
ldinghan Nov 6, 2024
301dd3d
Merge branch 'branch-collaborative-fe' of https://github.com/CS3219-A…
oeggy03 Nov 6, 2024
64f0dfd
Revamp collaborative page
ldinghan Nov 6, 2024
457b8df
Update match database when submitting
tjch-o Nov 6, 2024
496aa98
Merge branch 'branch-collaborative-fe' of https://github.com/CS3219-A…
oeggy03 Nov 6, 2024
06dd513
Implement GET endpoint for submissions
tjch-o Nov 6, 2024
7b2fadb
Add support for retrieving question with verifyRoom call to collab se…
oeggy03 Nov 6, 2024
a35da52
yassification
oeggy03 Nov 6, 2024
cc919c4
Enable updating of test cases
tjch-o Nov 6, 2024
b31038d
Implement prototype for videocall with WebRTC
wesho1107 Nov 6, 2024
11e1c75
Fix parsing issue for test cases
ldinghan Nov 7, 2024
dff35b6
Remove JSON parsing from add test case
ldinghan Nov 7, 2024
ed59f53
Improve code editor style
ldinghan Nov 7, 2024
74c842a
Fix difficulty not appearing
oeggy03 Nov 7, 2024
d43aa41
Add scrolling feature to question
ldinghan Nov 7, 2024
c8ab915
Add scrolling feature to question
ldinghan Nov 7, 2024
4d1e4d6
Reposition hidden text in code editor
ldinghan Nov 7, 2024
bc05a82
Add run code and submit button functionality
ldinghan Nov 7, 2024
73d58f5
Save submissions with errors
tjch-o Nov 7, 2024
f803da3
Fix duplicate video on refresh bug
wesho1107 Nov 7, 2024
8559e89
Merge branch 'code-execution-fe' into code-execution-video
wesho1107 Nov 7, 2024
0d7cf94
Handle duplicates when editing test cases
tjch-o Nov 7, 2024
da821f4
Fix styling issue and add tabs
wesho1107 Nov 7, 2024
fd69586
Integrate video into frontend with styling fixes
wesho1107 Nov 7, 2024
f323377
Add flex-grow to fix right empty spaces
wesho1107 Nov 7, 2024
b3b7efa
Merge pull request #39 from CS3219-AY2425S1/code-execution-fe
tjch-o Nov 7, 2024
d394137
Merge branch 'main' into code-execution-video
wesho1107 Nov 7, 2024
3c95b88
Merge pull request #40 from CS3219-AY2425S1/code-execution-video
wesho1107 Nov 7, 2024
3425ff0
Merge branch 'main' into PEERPREP-30-HistoryFeature
wesho1107 Nov 7, 2024
2c3fef2
Merge branch 'main' into PEERPREP-30-HistoryFeature
wesho1107 Nov 7, 2024
bbce3c3
Add skeleton for history-service backend
wesho1107 Nov 7, 2024
f5c477c
Implement the getMatchHistory filter
wesho1107 Nov 7, 2024
d9d8dbc
Refactor getting match history with user
tjch-o Nov 7, 2024
b3699fc
Implement frontend for MatchDetails and Submissionlist
wesho1107 Nov 7, 2024
2034987
Merge branch 'PEERPREP-30-HistoryFeature' of https://github.com/CS321…
wesho1107 Nov 7, 2024
2956e24
Implement fetching of submissions from history service
tjch-o Nov 7, 2024
ff85a1b
Fetch user by userId in history service
tjch-o Nov 7, 2024
9235cb7
Update dependencies
tjch-o Nov 7, 2024
d2411a3
Fix compile error
tjch-o Nov 7, 2024
c46a138
Remove ability of user clicks to exit match found dialogbox
ldinghan Nov 7, 2024
fe0fc24
Update output text when submitting code
ldinghan Nov 7, 2024
9a1f174
Redirect user to explore instead of dashboard on authentication
ldinghan Nov 7, 2024
2affd1f
Redirect user to explore on authentication
ldinghan Nov 7, 2024
048f74c
Add code submit success toast
wesho1107 Nov 8, 2024
1dcf1c7
Connect endpoint get-match-history
wesho1107 Nov 8, 2024
0df9acb
Add types for PastMatch and Submission
wesho1107 Nov 8, 2024
db3eb23
Add fetching of match with matchId
tjch-o Nov 8, 2024
c0b650d
Update docker
wesho1107 Nov 8, 2024
d00ad2b
Merge branch 'PEERPREP-30-HistoryFeature' of https://github.com/CS321…
wesho1107 Nov 8, 2024
1d3c49b
Made minor changes to get user in history service and user service so…
oeggy03 Nov 8, 2024
ec7cb80
Fix bug where api call is wrong
oeggy03 Nov 8, 2024
065f9f2
Connect endpoint for get-submissions in MatchDetailspAge
wesho1107 Nov 8, 2024
4b86e47
Fetch questionTitle
wesho1107 Nov 8, 2024
c7f0c9e
Add questionTitle to MatchDetailsPage
wesho1107 Nov 8, 2024
6420e8c
i hate docker
oeggy03 Nov 8, 2024
372af6f
Add CodeViewDialog for submissions
wesho1107 Nov 8, 2024
fc32c56
Merge branch 'PEERPREP-30-HistoryFeature' of https://github.com/CS321…
wesho1107 Nov 8, 2024
5764ac0
Change styling for hover:cursor and padding top
wesho1107 Nov 8, 2024
7194e02
add collab name
oeggy03 Nov 8, 2024
e6d7495
Merge branch 'PEERPREP-30-HistoryFeature' of https://github.com/CS321…
oeggy03 Nov 8, 2024
603dd9e
Merge pull request #41 from CS3219-AY2425S1/PEERPREP-30-HistoryFeature
oeggy03 Nov 8, 2024
e94a93c
Add time to roomId
tjch-o Nov 9, 2024
58db053
Merge pull request #42 from CS3219-AY2425S1/code-execution-backend
ldinghan Nov 9, 2024
9bcd1a6
update consumer a slight bit
oeggy03 Nov 9, 2024
eb18d85
Display public test cases on code run
ldinghan Nov 10, 2024
3ff7e7d
Remove logging messages
ldinghan Nov 10, 2024
8a9b7c6
Merge pull request #43 from CS3219-AY2425S1/code-execution-fe-improved
tjch-o Nov 10, 2024
fdbeabd
Change the collab-service backend code slightly so everything runs on…
oeggy03 Nov 10, 2024
0031cf1
Update gitignore
oeggy03 Nov 10, 2024
c9e8235
Modify frontend to use env
oeggy03 Nov 10, 2024
71bb2a1
slight changesto how user service loads up env
oeggy03 Nov 10, 2024
3ac0361
Change cookie configs
oeggy03 Nov 10, 2024
9af94b9
Merge pull request #44 from CS3219-AY2425S1/deployment
lunaroddity Nov 10, 2024
5a4c72a
make logout not break
oeggy03 Nov 10, 2024
e3c40c7
fix funny cookie
oeggy03 Nov 10, 2024
ec40269
Add cors origins to microservices
oeggy03 Nov 10, 2024
80d4a77
Fix npm run dev user service bug
tjch-o Nov 11, 2024
5d44c76
Implement user statistics in history-service
tjch-o Nov 12, 2024
789899b
Delete irrelevant files
oeggy03 Nov 12, 2024
7141b9b
Implement leave room logic and frontend
oeggy03 Nov 12, 2024
1cb84f5
Merge pull request #46 from CS3219-AY2425S1/exit-room
tjch-o Nov 12, 2024
3d7c015
Update progress timer to continue running after accepting match
ldinghan Nov 12, 2024
62ced00
Add redirecting message
ldinghan Nov 12, 2024
41789e2
Merge pull request #47 from CS3219-AY2425S1/matching-frontend
oeggy03 Nov 13, 2024
e1f3398
Merge branch 'main' into PEERPREP-30-HistoryFeature
wesho1107 Nov 13, 2024
b5b2aea
Integrate API endpoints to fetch userStatistics
wesho1107 Nov 13, 2024
067acd4
Update API endpoint to fetch total questions completed
wesho1107 Nov 13, 2024
60d67d4
Remove unnecessary files
tjch-o Nov 13, 2024
4ec9708
Add skeleton for better user experience
wesho1107 Nov 13, 2024
69be8aa
Add pagination functionality
wesho1107 Nov 13, 2024
510ed3a
Refactor HistoryTable
wesho1107 Nov 13, 2024
d9d03ad
Refactor QuestionTable
wesho1107 Nov 13, 2024
c7aa304
Replace QuestionTable with new data-table
wesho1107 Nov 13, 2024
7dd4039
Improve UX of submission card
wesho1107 Nov 13, 2024
c16e59b
Fix static languages not compiling
tjch-o Nov 13, 2024
d99a821
Improve code editor with live cursor and selection
wesho1107 Nov 13, 2024
641793c
Adjust timeout and provide support to our beloved C++ users
tjch-o Nov 13, 2024
5d7fdf7
Merge pull request #48 from CS3219-AY2425S1/final-nits
oeggy03 Nov 13, 2024
9258801
Merge branch 'main' of https://github.com/CS3219-AY2425S1/cs3219-ay24…
oeggy03 Nov 13, 2024
ba57eb5
Merge pull request #45 from CS3219-AY2425S1/PEERPREP-30-HistoryFeature
oeggy03 Nov 13, 2024
c599e38
User now able to rejoin room if they navigate out, on the explore page.
oeggy03 Nov 13, 2024
cc45376
change ugly button
oeggy03 Nov 13, 2024
c604f27
Merge pull request #49 from CS3219-AY2425S1/see-active-rooms
lunaroddity Nov 13, 2024
40a1598
Display error output when code does not work at all
tjch-o Nov 13, 2024
ba5c69f
Merge branch 'main' into final-nits
tjch-o Nov 13, 2024
dbdfe63
Clear error output when submitting
tjch-o Nov 13, 2024
b112874
Fix bug when no camera detected
wesho1107 Nov 13, 2024
5120db6
Merge pull request #50 from CS3219-AY2425S1/final-nits
wesho1107 Nov 13, 2024
32218e6
Add additional enhancement buttons
wesho1107 Nov 13, 2024
26b23e6
Merge pull request #51 from CS3219-AY2425S1/Enhancement-Remove-Redundant
wesho1107 Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
dist

.github

.env
backend/*/combined.log
backend/*/error.log
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 4,
"printWidth": 80
}
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/bzPrOe11)

# CS3219 Project (PeerPrep) - AY2425S1
## Group: Gxx

### Note:
- You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice.
- In the latter scenario, you should enable sub-modules on this GitHub classroom repository to manage the development/deployment **AND** add your mentor to the individual repositories as a collaborator.
- The teaching team should be given access to the repositories as we may require viewing the history of the repository in case of any disputes or disagreements.
## Group: G18

Ensure Docker has been installed before running the following commands:
```
docker-compose up --build
```

### Note:

- You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice.
- In the latter scenario, you should enable sub-modules on this GitHub classroom repository to manage the development/deployment **AND** add your mentor to the individual repositories as a collaborator.
- The teaching team should be given access to the repositories as we may require viewing the history of the repository in case of any disputes or disagreements.
13 changes: 13 additions & 0 deletions backend/code-execution-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 5005

CMD ["npm", "run", "dev"]
130 changes: 130 additions & 0 deletions backend/code-execution-service/execute-code/executeCodeController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import axios from 'axios'
import { Response } from 'express'
import logger from '../utils/logger'
import {
CodeExecutionRequest,
ExecutionResult,
TestCase,
languageExtensions,
} from '../models/types'
import {
formatTestInput,
countNumberOfPassedTestCases,
passedAllTestCases
} from '../utils/utils'
import { error } from 'winston'

const executeUserCode = async (
req: CodeExecutionRequest,
res: Response,
): Promise<Response> => {
const { questionId, code, language } = req.body

if (!questionId || !code || !language) {
return res
.status(400)
.json({ message: 'Question ID, code and language are required' })
}

let question: any
let testCases: TestCase[]
try {
const getQuestionRes = await axios.get(
`${process.env.QUESTION_SERVICE_URL}/get-questions`,
{
params: { questionId },
validateStatus: (status) => status >= 200 && status < 500,
},
)

if (!getQuestionRes.data || getQuestionRes.data.length === 0) {
logger.error('Question not found')
return res.status(400).json({ message: 'Question not found' })
}

question = getQuestionRes.data[0]
testCases = question.testCases
} catch (e) {
logger.error('Error fetching question details', e)
return res
.status(500)
.json({ message: 'Error fetching question details' })
}

const formattedInput = testCases
.map((tc) => formatTestInput(tc.input))
.join('\n')

const fileName = `q${questionId}.${languageExtensions.get(language == 'Cpp' ? 'c++' : language.toLowerCase())}`
let payload = {
language: language.toLowerCase(),
stdin: formattedInput,
files: [
{
name: fileName,
content: code,
},
],
compileOnly: false,
wait: true,
}

try {
const executeCodeRes = await axios.post(
`${process.env.CODE_COMPILER_URL}`,
payload,
{
headers: {
'Content-Type': 'application/json',
'x-rapidapi-host': 'onecompiler-apis.p.rapidapi.com',
'x-rapidapi-key': process.env.ACCESS_TOKEN,
},
validateStatus: (status) => status >= 200 && status < 500,
},
)

if (executeCodeRes.data.stderr) {
let errorMsg = executeCodeRes.data.stderr
console.log(errorMsg)
logger.error(
'Error appeared when executing code',
{ error: errorMsg },
)
return res.status(400).json({
success: false,
error: executeCodeRes.data.stderr,
compilationOutput: executeCodeRes.data.compilationOutput,
})
}

const codeOutput = (executeCodeRes.data.stdout || '').trim().split('\n')
const results: ExecutionResult[] = testCases.map((tc, i) => ({
input: tc.input,
expected: tc.expected,
output: codeOutput[i]?.trim() || '',
passed: String(tc.expected) == codeOutput[i]?.trim(),
}))

const response = {
success: passedAllTestCases(results),
results,
testCasesPassed: countNumberOfPassedTestCases(results),
testCasesTotal: testCases.length,
compilationOutput: executeCodeRes.data.compilationOutput,
error: executeCodeRes.data.stderr,
}

const submissionOutcomeMsg = response.success
? 'All test cases passed'
: 'Some test cases failed'
logger.info(`Code execution results: ${submissionOutcomeMsg}`)
return res.status(200).json(response)
} catch (e) {
logger.error('Error executing code', e)
return res
.status(500)
.json({ message: 'Error executing code with OneCompiler' })
}
}

export { executeUserCode }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RequestHandler, Router } from 'express'
import { executeUserCode } from './executeCodeController'

const router = Router()
router.post('/execute-code', executeUserCode as unknown as RequestHandler)

export { router }
19 changes: 19 additions & 0 deletions backend/code-execution-service/get-code/getCodeController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Response } from "express"
import Submission from "../models/submission"
import logger from "../utils/logger"
import { GetCodeRequest } from "../models/types"

const getUserCode = async (req: GetCodeRequest, res: Response) => {
const { matchId } = req.params

try {
const submissions = await Submission.find({ matchId })
logger.info(`Successfully fetched submissions for match ${matchId}`)
return res.status(200).json(submissions)
} catch (e) {
logger.error(`Error fetching submissions for match ${matchId}`)
return res.status(500).json({ message: 'Error fetching submissions' })
}
}

export { getUserCode }
7 changes: 7 additions & 0 deletions backend/code-execution-service/get-code/getCodeRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RequestHandler, Router } from 'express'
import { getUserCode } from './getCodeController'

const router = Router()
router.get('/get-code/:matchId', getUserCode as unknown as RequestHandler)

export { router }
30 changes: 30 additions & 0 deletions backend/code-execution-service/models/submission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Schema, model, models, Document } from 'mongoose';

export interface ISubmission extends Document {
matchId: string,
questionId: number
language: string
code: string
solved: boolean
testCasesPassed: number
testCasesTotal: number
}

const SubmissionSchema = new Schema<ISubmission>(
{
matchId: { type: String, required: true, unique: true, index: true },
questionId: { type: Number, required: true, index: true },
language: { type: String, required: true },
code: { type: String, required: true, default: '' },
solved: { type: Boolean },
testCasesPassed: { type: Number, default: 0 },
testCasesTotal: { type: Number, default: 0 },
},
{
timestamps: true,
}
);

const Submission = models.Submission || model<ISubmission>('Submission', SubmissionSchema);

export default Submission;
47 changes: 47 additions & 0 deletions backend/code-execution-service/models/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Request, Response } from 'express'
import { Types } from 'mongoose'

export interface CodeExecutionRequest extends Request {
body: {
questionId: number
code: string
language: string
}
}

export interface CodeSubmissionRequest extends Request {
body: {
questionId: number
matchId: number
code: string
language: string
}
}

export interface GetCodeRequest extends Request {
params: {
matchId: string
}
}

export interface TestCase {
input: any
expected: any
}

export interface ExecutionResult {
input: any,
expected: any,
output: any
passed: boolean
}

export const languageExtensions = new Map([
['javascript', 'js'],
['python', 'py'],
['java', 'java'],
['c', 'c'],
['c++', 'cpp'],
['go', 'go'],
['typescript', 'ts']
])
Loading