You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. Create the `.env` file from copying the `.env.example`, and copy the firebase JSON file into execution-service/ fill in the `FIREBASE_CREDENTIAL_PATH` with the path of the firebase credential JSON file.
12
+
13
+
### Running the Application
14
+
15
+
To start the server, run the following command:
16
+
17
+
```bash
18
+
go run main.go
19
+
```
20
+
21
+
The server will be available at http://localhost:8083.
22
+
23
+
## Running the Application via Docker
24
+
25
+
To run the application via Docker, run the following command:
26
+
27
+
```bash
28
+
docker build -t execution-service .
29
+
```
30
+
31
+
```bash
32
+
docker run -p 8083:8083 --env-file .env -d execution-service
33
+
```
34
+
35
+
The server will be available at http://localhost:8083.
36
+
37
+
## API Endpoints
38
+
39
+
-`POST /tests/populate`
40
+
-`GET /tests/{questionDocRefId}/`
41
+
-`POST /tests/{questionDocRefId}/execute`
42
+
-`POST /tests/{questionDocRefId}/submit`
43
+
44
+
## Managing Firebase
45
+
46
+
To reset and repopulate the database, run the following command:
47
+
48
+
```bash
49
+
go run main.go
50
+
```
51
+
52
+
## Repopulate test cases
53
+
54
+
To repopulate test cases, you need to repopulate the questions in the question-service, which will automatically call the execution-service to populate the test cases.
55
+
56
+
In question-service, run the following command:
57
+
58
+
```bash
59
+
go run main.go -populate
60
+
```
61
+
62
+
## API Documentation
63
+
64
+
`GET /tests/{questionDocRefId}/`
65
+
66
+
To read visible test cases via a question ID, run the following command:
67
+
68
+
```bash
69
+
curl -X GET http://localhost:8083/tests/{questioinDocRefId}/ \
70
+
-H "Content-Type: application/json"
71
+
```
72
+
73
+
The following json format will be returned:
74
+
75
+
```json
76
+
[
77
+
{
78
+
"input":"hello",
79
+
"expected":"olleh"
80
+
}
81
+
]
82
+
```
83
+
84
+
`POST /tests/{questionDocRefId}/execute`
85
+
86
+
To execute test cases via a question ID without custom test cases, run the following command, with custom code and language:
87
+
88
+
```bash
89
+
curl -X POST http://localhost:8083/tests/{questioinDocRefId}/execute \
90
+
-H "Content-Type: application/json" \
91
+
-d '{
92
+
"code": "name = input()\nprint(name[::-1])",
93
+
"language": "Python"
94
+
}'
95
+
```
96
+
97
+
The following json format will be returned:
98
+
99
+
```json
100
+
{
101
+
"visibleTestResults":[
102
+
{
103
+
"input":"hello",
104
+
"expected":"olleh",
105
+
"actual":"olleh",
106
+
"passed":true,
107
+
"error":""
108
+
}
109
+
],
110
+
"customTestResults":null
111
+
}
112
+
```
113
+
114
+
To execute visible and custom test cases via a question ID with custom test cases, run the following command, with custom code, language and custom test cases:
115
+
116
+
```bash
117
+
curl -X POST http://localhost:8083/tests/{questioinDocRefId}/execute \
To submit a solution and execute visible and hidden test cases via a question ID, run the following command, with custom code and language:
161
+
162
+
```bash
163
+
curl -X POST http://localhost:8083/tests/{questioinDocRefId}/submit \
164
+
-H "Content-Type: application/json" \
165
+
-d '{
166
+
"title": "Example Title",
167
+
"code": "name = input()\nprint(name[::-1])",
168
+
"language": "Python",
169
+
"user": "user123",
170
+
"matchedUser": "user456",
171
+
"matchedTopics": ["topic1", "topic2"],
172
+
"questionDifficulty": "Medium",
173
+
"questionTopics": ["Loops", "Strings"]
174
+
}'
175
+
```
176
+
177
+
The following json format will be returned:
178
+
179
+
```json
180
+
{
181
+
"visibleTestResults":[
182
+
{
183
+
"input":"hello",
184
+
"expected":"olleh",
185
+
"actual":"olleh",
186
+
"passed":true,
187
+
"error":""
188
+
}
189
+
],
190
+
"hiddenTestResults":{
191
+
"passed":2,
192
+
"total":2
193
+
},
194
+
"status":"Accepted"
195
+
}
196
+
```
197
+
198
+
If compilation error exists or any of the tests (visible and hidden) fails, status "Attempted" will be returned:
199
+
200
+
```json
201
+
{
202
+
"visibleTestResults":[
203
+
{
204
+
"input":"hello",
205
+
"expected":"olleh",
206
+
"actual":"",
207
+
"passed":false,
208
+
"error":"Command execution failed: Traceback (most recent call last):\n File \"/tmp/4149249165.py\", line 2, in \u003cmodule\u003e\n prit(name[::-1])\n ^^^^\nNameError: name 'prit' is not defined. Did you mean: 'print'?\n: %!w(*exec.ExitError=\u0026{0x4000364678 []})"
0 commit comments