Skip to content

Commit 94f5762

Browse files
authored
Merge pull request #19 from CS3219-AY2425S1/feat/question-service
Feat/question service
2 parents b64a990 + 4a1a7a7 commit 94f5762

16 files changed

+1620
-0
lines changed

question-service/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dockerfile
2+
.dockerignore
3+
node_modules
4+
npm-debug.log
5+
dist

question-service/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
.env.dev
3+
/dist

question-service/.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm test

question-service/.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
build

question-service/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"printWidth": 80
6+
}

question-service/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:18-alpine
2+
3+
# Copy package.json and package-lock.json
4+
COPY package*.json ./
5+
6+
# Install any dependencies
7+
RUN npm install
8+
9+
# Bundle app source inside the Docker image
10+
COPY src ./src
11+
12+
COPY tsconfig.json ./tsconfig.json
13+
14+
RUN npm run build
15+
16+
# Make port 3001 available to the world outside this container
17+
ENV PORT=4001
18+
19+
EXPOSE ${PORT}
20+
21+
# Define the command to run your app
22+
CMD ["npm", "start"]

question-service/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Question Service
2+
3+
## Setup
4+
5+
Run the following command to install the dependencies
6+
7+
```bash
8+
docker build -t question-service . --no-cache
9+
docker run -p 4001:4001 --env-file .env.dev question-service
10+
```
11+
12+
## Routes Endpoint
13+
14+
- GET /questions/ - get all coding questions
15+
- GET /userQuestions/ - get all user questions
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"info": {
3+
"_postman_id": "04ba6e0b-d75d-4331-a2d1-e4bffdb608ca",
4+
"name": "question-service",
5+
"description": "# 🚀 Get started here\n\nThis template guides you through CRUD operations (GET, POST, PUT, DELETE), variables, and tests.\n\n## 🔖 **How to use this template**\n\n#### **Step 1: Send requests**\n\nRESTful APIs allow you to perform CRUD operations using the POST, GET, PUT, and DELETE HTTP methods.\n\nThis collection contains each of these [request](https://learning.postman.com/docs/sending-requests/requests/) types. Open each request and click \"Send\" to see what happens.\n\n#### **Step 2: View responses**\n\nObserve the response tab for status code (200 OK), response time, and size.\n\n#### **Step 3: Send new Body data**\n\nUpdate or add new data in \"Body\" in the POST request. Typically, Body data is also used in PUT request.\n\n```\n{\n \"name\": \"Add your name in the body\"\n}\n\n ```\n\n#### **Step 4: Update the variable**\n\nVariables enable you to store and reuse values in Postman. We have created a [variable](https://learning.postman.com/docs/sending-requests/variables/) called `base_url` with the sample request [https://postman-api-learner.glitch.me](https://postman-api-learner.glitch.me). Replace it with your API endpoint to customize this collection.\n\n#### **Step 5: Add tests in the \"Scripts\" tab**\n\nAdding tests to your requests can help you confirm that your API is working as expected. You can write test scripts in JavaScript and view the output in the \"Test Results\" tab.\n\n<img src=\"https://content.pstmn.io/fa30ea0a-373d-4545-a668-e7b283cca343/aW1hZ2UucG5n\" alt=\"\" height=\"1530\" width=\"2162\">\n\n## 💪 Pro tips\n\n- Use folders to group related requests and organize the collection.\n \n- Add more [scripts](https://learning.postman.com/docs/writing-scripts/intro-to-scripts/) to verify if the API works as expected and execute workflows.\n \n\n## 💡Related templates\n\n[API testing basics](https://go.postman.co/redirect/workspace?type=personal&collectionTemplateId=e9a37a28-055b-49cd-8c7e-97494a21eb54&sourceTemplateId=ddb19591-3097-41cf-82af-c84273e56719) \n[API documentation](https://go.postman.co/redirect/workspace?type=personal&collectionTemplateId=e9c28f47-1253-44af-a2f3-20dce4da1f18&sourceTemplateId=ddb19591-3097-41cf-82af-c84273e56719) \n[Authorization methods](https://go.postman.co/redirect/workspace?type=personal&collectionTemplateId=31a9a6ed-4cdf-4ced-984c-d12c9aec1c27&sourceTemplateId=ddb19591-3097-41cf-82af-c84273e56719)",
6+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
7+
"_exporter_id": "27666912"
8+
},
9+
"item": [
10+
{
11+
"name": "get questions",
12+
"event": [
13+
{
14+
"listen": "test",
15+
"script": {
16+
"exec": [
17+
"pm.test(\"Status code is 200\", function () {",
18+
" pm.response.to.have.status(200);",
19+
"});"
20+
],
21+
"type": "text/javascript",
22+
"packages": {}
23+
}
24+
}
25+
],
26+
"request": {
27+
"method": "GET",
28+
"header": [],
29+
"url": {
30+
"raw": "{{base_url}}/questions/",
31+
"host": [
32+
"{{base_url}}"
33+
],
34+
"path": [
35+
"questions",
36+
""
37+
]
38+
},
39+
"description": "This is a GET request and it is used to \"get\" data from an endpoint. There is no request body for a GET request, but you can use query parameters to help specify the resource you want data on (e.g., in this request, we have `id=1`).\n\nA successful GET response will have a `200 OK` status, and should include some kind of response body - for example, HTML web content or JSON data."
40+
},
41+
"response": []
42+
},
43+
{
44+
"name": "Delete data",
45+
"event": [
46+
{
47+
"listen": "test",
48+
"script": {
49+
"exec": [
50+
"pm.test(\"Successful DELETE request\", function () {",
51+
" pm.expect(pm.response.code).to.be.oneOf([200, 202, 204]);",
52+
"});",
53+
""
54+
],
55+
"type": "text/javascript",
56+
"packages": {}
57+
}
58+
}
59+
],
60+
"protocolProfileBehavior": {
61+
"disableBodyPruning": true
62+
},
63+
"request": {
64+
"method": "GET",
65+
"header": [],
66+
"body": {
67+
"mode": "raw",
68+
"raw": "",
69+
"options": {
70+
"raw": {
71+
"language": "json"
72+
}
73+
}
74+
},
75+
"url": {
76+
"raw": "{{base_url}}/userquestions/",
77+
"host": [
78+
"{{base_url}}"
79+
],
80+
"path": [
81+
"userquestions",
82+
""
83+
]
84+
},
85+
"description": "This is a DELETE request, and it is used to delete data that was previously created via a POST request. You typically identify the entity being updated by including an identifier in the URL (eg. `id=1`).\n\nA successful DELETE request typically returns a `200 OK`, `202 Accepted`, or `204 No Content` response code."
86+
},
87+
"response": []
88+
}
89+
],
90+
"event": [
91+
{
92+
"listen": "prerequest",
93+
"script": {
94+
"type": "text/javascript",
95+
"exec": [
96+
""
97+
]
98+
}
99+
},
100+
{
101+
"listen": "test",
102+
"script": {
103+
"type": "text/javascript",
104+
"exec": [
105+
""
106+
]
107+
}
108+
}
109+
],
110+
"variable": [
111+
{
112+
"key": "id",
113+
"value": "1"
114+
},
115+
{
116+
"key": "base_url",
117+
"value": "localhost:4001",
118+
"type": "string"
119+
}
120+
]
121+
}

question-service/package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "question-service",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"directories": {
6+
"test": "test"
7+
},
8+
"scripts": {
9+
"start": "npx tsc && node dist/app.js",
10+
"build": "tsc",
11+
"format": "prettier --write \"src/**/*.ts\"",
12+
"test": "echo \"Error: no test specified\" && exit 1",
13+
"prepare": "husky"
14+
},
15+
"keywords": [],
16+
"author": "",
17+
"license": "ISC",
18+
"description": "",
19+
"dependencies": {
20+
"dotenv": "^16.4.5",
21+
"express": "^4.21.0",
22+
"mongodb": "^6.9.0",
23+
"mongoose": "^8.6.3",
24+
"prettier": "^3.3.3"
25+
},
26+
"devDependencies": {
27+
"@types/dotenv": "^6.1.1",
28+
"@types/express": "^4.17.21",
29+
"@types/mongoose": "^5.11.96",
30+
"@types/node": "^22.6.1",
31+
"husky": "^9.1.6",
32+
"nodemon": "^3.1.7",
33+
"ts-node": "^10.9.2",
34+
"typescript": "^5.6.2"
35+
}
36+
}

0 commit comments

Comments
 (0)