Skip to content

Commit c813531

Browse files
committed
Merge branch 'development' of https://github.com/ruiqi7/peer-prep into feature/matching-websocket
2 parents 46c7bd6 + 08fa523 commit c813531

File tree

17 files changed

+164
-131
lines changed

17 files changed

+164
-131
lines changed

backend/.env.sample

Lines changed: 0 additions & 16 deletions
This file was deleted.

backend/README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22

33
> Before proceeding to each microservice for more instructions:
44
5-
1. Set-up either a local or cloud MongoDB.
5+
1. Set up cloud MongoDB if not using docker. We recommend this if you are just testing out each microservice separately to avoid needing to manually set up multiple instances of local MongoDB. Else, if you are using docker-compose.yml to run PeerPrep, check out the READMEs in the different backend microservices to set up the env for the local MongoDB instances.
66

7-
2. Set-up Firebase.
7+
2. Set up Firebase.
88

99
3. Follow the instructions [here](https://nodejs.org/en/download/package-manager) to set up Node v20.
1010

11-
## Setting-up local MongoDB (only if you are using Docker)
12-
13-
1. In the `backend` directory, create a copy of the `.env.sample` file and name it `.env`.
14-
15-
2. To set up credentials for the MongoDB database, update `MONGO_INITDB_ROOT_USERNAME`, `MONGO_INITDB_ROOT_PASSWORD` of the `.env` file.
16-
17-
3. Your local Mongo URI will be `mongodb://<MONGO_INITDB_ROOT_USERNAME>:<MONGO_INITDB_ROOT_PASSWORD>@mongo:27017/`. Take note of it as we will be using in the `.env` files in the various microservices later on.
18-
19-
4. You can view the MongoDB collections locally using Mongo Express. To set up Mongo Express, update `ME_CONFIG_BASICAUTH_USERNAME` and `ME_CONFIG_BASICAUTH_PASSWORD`. The username and password will be the login credentials when you access Mongo Express at http://localhost:8081.
20-
2111
## Setting-up cloud MongoDB (in production)
2212

2313
> This guide references the [user-service README in the PeerPrep-UserService repository](https://github.com/CS3219-AY2425S1/PeerPrep-UserService/blob/main/user-service/README.md)
@@ -97,6 +87,8 @@
9787

9888
## Setting-up Firebase
9989

90+
> For ease of testing, you can set up just one firebase to use across all the microservices that need it.
91+
10092
1. Go to https://console.firebase.google.com/u/0/.
10193

10294
2. Create a project and choose a project name. Navigate to `Storage` and click on it to activate it.

backend/matching-service/.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NODE_ENV=development
2-
PORT=3002
2+
SERVICE_PORT=3002
33

44
ORIGINS=http://localhost:5173,http://127.0.0.1:5173
55

backend/matching-service/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ io.on("connection", (socket) => {
1717
handleWebsocketMatchEvents(socket);
1818
});
1919

20-
const PORT = process.env.PORT || 3002;
20+
const PORT = process.env.SERVICE_PORT || 3002;
2121

2222
if (process.env.NODE_ENV !== "test") {
2323
connectToRabbitMq()
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
NODE_ENV=development
2-
PORT=3000
3-
4-
MONGO_CLOUD_URI=<MONGO_CLOUD_URI>
5-
MONGO_LOCAL_URI=<MONGO_LOCAL_URI>
2+
SERVICE_PORT=3000
63

74
FIREBASE_PROJECT_ID=<FIREBASE_PROJECT_ID>
85
FIREBASE_PRIVATE_KEY=<FIREBASE_PRIVATE_KEY>
@@ -14,3 +11,22 @@ ORIGINS=http://localhost:5173,http://127.0.0.1:5173
1411
USER_SERVICE_URL=http://user-service:3001/api
1512

1613
MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/
14+
15+
# if using cloud MongoDB, replace with actual URI (run service separately)
16+
MONGO_CLOUD_URI=<MONGO_CLOUD_URI>
17+
18+
# if using local MongoDB (run service with docker-compose)
19+
## MongoDB credentials
20+
MONGO_INITDB_ROOT_USERNAME=root
21+
MONGO_INITDB_ROOT_PASSWORD=example
22+
23+
## Mongo Express credentials
24+
ME_CONFIG_BASICAUTH_USERNAME=admin
25+
ME_CONFIG_BASICAUTH_PASSWORD=password
26+
27+
## Do not change anything below this line
28+
ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_INITDB_ROOT_USERNAME}
29+
ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
30+
ME_CONFIG_MONGODB_URL=mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@question-service-mongo:27017/
31+
32+
MONGO_LOCAL_URI=mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@question-service-mongo:27017/

backend/question-service/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88

99
2. To connect to your cloud MongoDB instead of your local MongoDB, set the `NODE_ENV` to `production` instead of `development`.
1010

11-
3. Update `MONGO_CLOUD_URI`, `MONGO_LOCAL_URI`, `FIREBASE_PROJECT_ID`, `FIREBASE_PRIVATE_KEY`, `FIREBASE_CLIENT_EMAIL`, `FIREBASE_STORAGE_BUCKET`.
11+
3. Update `FIREBASE_PROJECT_ID`, `FIREBASE_PRIVATE_KEY`, `FIREBASE_CLIENT_EMAIL`, `FIREBASE_STORAGE_BUCKET`, `MONGO_CLOUD_URI` with the env variables obtained from following the instructions in the backend README. Then update `MONGO_INITDB_ROOT_USERNAME`, `MONGO_INITDB_ROOT_PASSWORD` to change your MongoDB credentials if necessary.
12+
13+
4. You can view the MongoDB collections locally using Mongo Express. To set up Mongo Express, update `ME_CONFIG_BASICAUTH_USERNAME` and `ME_CONFIG_BASICAUTH_PASSWORD`. The username and password will be the login credentials when you access Mongo Express at http://localhost:8081.
1214

1315
## Running Question Service without Docker
1416

17+
> Make sure you have the cloud MongoDB URI in your .env file and set NODE_ENV to production already.
18+
1519
1. Open Command Line/Terminal and navigate into the `question-service` directory.
1620

1721
2. Run the command: `npm install`. This will install all the necessary dependencies.

backend/question-service/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import app from "./app.ts";
22
import connectDB from "./config/db.ts";
33

4-
const PORT = process.env.PORT || 3000;
4+
const PORT = process.env.SERVICE_PORT || 3000;
55

66
if (process.env.NODE_ENV !== "test") {
77
connectDB()

backend/question-service/src/controllers/questionController.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,24 @@ export const readCategories = async (
251251
res: Response,
252252
): Promise<void> => {
253253
try {
254-
const uniqueCats = await Question.distinct("category");
254+
// const uniqueCats = await Question.distinct("category");
255255

256+
// res.status(200).json({
257+
// message: CATEGORIES_RETRIEVED_MESSAGE,
258+
// categories: sortAlphabetically(uniqueCats),
259+
// });
256260
res.status(200).json({
257261
message: CATEGORIES_RETRIEVED_MESSAGE,
258-
categories: sortAlphabetically(uniqueCats),
262+
categories: sortAlphabetically([
263+
"Strings",
264+
"Algorithms",
265+
"Data Structures",
266+
"Bit Manipulation",
267+
"Recursion",
268+
"Dynamic Programming",
269+
"Arrays",
270+
"Tree",
271+
]),
259272
});
260273
} catch (error) {
261274
res.status(500).json({ message: SERVER_ERROR_MESSAGE, error });

backend/question-service/src/scripts/seed.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,98 +11,84 @@ export async function seedQuestions() {
1111
description:
1212
"Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure. \n\n![image](https://firebasestorage.googleapis.com/v0/b/peerprep-c3bd1.appspot.com/o/07148757-21b2-4c20-93e0-d8bef1b3560d?alt=media)",
1313
complexity: "Hard",
14-
category: ["Tree", "Design"],
14+
category: ["Tree"],
1515
},
1616
{
1717
title: "Two Sum",
1818
description:
1919
"Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assume that each input would have **exactly one solution**, and you may not use the same element twice. You can return the answer in any order.",
2020
complexity: "Easy",
21-
category: ["Array", "Hash Table"],
22-
},
23-
{
24-
title: "Add Two Numbers",
25-
description:
26-
"You are given two non-empty linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself.",
27-
complexity: "Medium",
28-
category: ["Linked List", "Math"],
21+
category: ["Arrays"],
2922
},
3023
{
3124
title: "Longest Substring Without Repeating Characters",
3225
description:
3326
"Given a string `s`, find the length of the **longest substring** without repeating characters.",
3427
complexity: "Medium",
35-
category: ["Hash Table", "Two Pointers", "String", "Sliding Window"],
28+
category: ["Strings"],
3629
},
3730
{
3831
title: "Median of Two Sorted Arrays",
3932
description:
4033
"Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return the median of the two sorted arrays.",
4134
complexity: "Hard",
42-
category: ["Array", "Binary Search", "Divide and Conquer"],
35+
category: ["Arrays"],
4336
},
4437
{
4538
title: "Longest Palindromic Substring",
4639
description:
4740
"Given a string `s`, return the **longest palindromic substring** in `s`.",
4841
complexity: "Medium",
49-
category: ["String", "Dynamic Programming"],
42+
category: ["Strings", "Dynamic Programming"],
5043
},
5144
{
5245
title: "ZigZag Conversion",
5346
description:
5447
"The string `PAYPALISHIRING` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `PAHNAPLSIIGYIR` Write the code that will take a string and make this conversion given a number of rows.",
5548
complexity: "Medium",
56-
category: ["String"],
49+
category: ["Strings"],
5750
},
5851
{
5952
title: "Reverse Integer",
6053
description:
6154
"Given a signed 32-bit integer `x`, return `x` with its digits reversed. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-2^31, 2^31 - 1]`, then return 0.",
6255
complexity: "Easy",
63-
category: ["Math"],
56+
category: ["Strings"],
6457
},
6558
{
6659
title: "String to Integer (atoi)",
6760
description:
6861
"Implement the `myAtoi(string s)` function, which converts a string to a 32-bit signed integer (similar to C/C++'s `atoi` function).",
6962
complexity: "Medium",
70-
category: ["Math", "String"],
71-
},
72-
{
73-
title: "Palindrome Number",
74-
description:
75-
"Given an integer `x`, return `true` if `x` is a palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, `121` is palindrome while `123` is not.",
76-
complexity: "Easy",
77-
category: ["Math"],
63+
category: ["Strings"],
7864
},
7965
{
8066
title: "Regular Expression Matching",
8167
description:
8268
"Given an input string `s` and a pattern `p`, implement regular expression matching with support for `'.'` and `'*'` where: - `'.'` Matches any single character.​​​​ - `'*'` Matches zero or more of the preceding element.",
8369
complexity: "Hard",
84-
category: ["String", "Dynamic Programming", "Backtracking"],
70+
category: ["Strings", "Dynamic Programming"],
8571
},
8672
{
8773
title: "Container With Most Water",
8874
description:
8975
"Given `n` non-negative integers `a1, a2, ..., an`, where each represents a point at coordinate `(i, ai)`. `n` vertical lines are drawn such that the two endpoints of the line `i` is at `(i, ai)` and `(i, 0)`. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.",
9076
complexity: "Medium",
91-
category: ["Array", "Two Pointers"],
77+
category: ["Arrays"],
9278
},
9379
{
9480
title: "Integer to Roman",
9581
description:
9682
"Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`. Given an integer, convert it to a roman numeral.",
9783
complexity: "Medium",
98-
category: ["Math", "String"],
84+
category: ["Strings"],
9985
},
10086
{
10187
title: "Roman to Integer",
10288
description:
10389
"Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`. Given a roman numeral, convert it to an integer.",
10490
complexity: "Easy",
105-
category: ["Math", "String"],
91+
category: ["Strings"],
10692
},
10793
];
10894

backend/user-service/.env.sample

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
NODE_ENV=development
2-
PORT=3001
3-
4-
MONGO_CLOUD_URI=<MONGO_CLOUD_URI>
5-
MONGO_LOCAL_URI=<MONGO_LOCAL_URI>
2+
SERVICE_PORT=3001
63

74
# Secret for creating JWT signature
85
JWT_SECRET=<JWT_SECRET>
@@ -34,4 +31,23 @@ REDIS_URI=redis://redis:6379 # Uncomment if you're running the user service usin
3431

3532
# Test
3633
MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/
37-
REDIS_URI_TEST=redis://test-redis:6379
34+
REDIS_URI_TEST=redis://test-redis:6379
35+
36+
# if using cloud MongoDB, replace with actual URI (run service separately)
37+
MONGO_CLOUD_URI=<MONGO_CLOUD_URI>
38+
39+
# if using local MongoDB (run service with docker-compose)
40+
## MongoDB credentials
41+
MONGO_INITDB_ROOT_USERNAME=root
42+
MONGO_INITDB_ROOT_PASSWORD=example
43+
44+
## Mongo Express credentials
45+
ME_CONFIG_BASICAUTH_USERNAME=admin
46+
ME_CONFIG_BASICAUTH_PASSWORD=password
47+
48+
## Do not change anything below this line
49+
ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_INITDB_ROOT_USERNAME}
50+
ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
51+
ME_CONFIG_MONGODB_URL=mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@user-service-mongo:27017/
52+
53+
MONGO_LOCAL_URI=mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@user-service-mongo:27017/

0 commit comments

Comments
 (0)