Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerize question and user services #36

Merged
merged 113 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
e6dced5
Merge branch 'setting-up-react'
tsulim Sep 11, 2024
f9d7b2f
Merge remote-tracking branch 'upstream/main'
tsulim Sep 11, 2024
5b57a26
Remove dependency in backend and change command to start backend server
iynixil Sep 11, 2024
4881518
Change port used in backend server
iynixil Sep 11, 2024
710c5cf
Solve merge conflict
iynixil Sep 11, 2024
cb22648
Merge pull request #4 from CS3219-AY2425S1/main
AndrewOng2066 Sep 11, 2024
edc57f7
Merge remote-tracking branch 'upstream/main'
tsulim Sep 11, 2024
cb422cf
Merge pull request #5 from CS3219-AY2425S1/main
AndrewOng2066 Sep 13, 2024
9554549
Update package-lock.json to be same as main
iynixil Sep 20, 2024
32422d1
Display questions data from database
xuelinglow Sep 23, 2024
ac89783
Make changes to css files
xuelinglow Sep 23, 2024
1291721
Make some changes to css. Implement form to add questions to database
xuelinglow Sep 23, 2024
1a047ab
Make some minor changes to css
xuelinglow Sep 23, 2024
0168985
Make changes according to coding standard
xuelinglow Sep 24, 2024
fc5b73d
Create register account function
Sep 24, 2024
14d2030
Merge pull request #10 from AndrewOng2066/register_user
AndrewOng2066 Sep 24, 2024
26b5247
Merge remote-tracking branch 'upstream/user_branch_Andrew' into user-…
iynixil Sep 25, 2024
f87bcf8
Add user login API
iynixil Sep 25, 2024
a99754e
Fix login API to get encrypted password from database
iynixil Sep 25, 2024
7f86204
Fix user login API to retrieve username from database
iynixil Sep 25, 2024
24de94c
Merge pull request #9 from CS3219-AY2425S1/question_branch_xl
iynixil Sep 25, 2024
7aed41f
Add login route to frontend
iynixil Sep 26, 2024
6c07593
Add login page UI and styling
iynixil Sep 26, 2024
500cec1
Add logout API
iynixil Sep 26, 2024
e89e2f9
Update password input field to be hidden
iynixil Sep 26, 2024
a645b65
Merge remote-tracking branch 'upstream/question_branch_xl'
whitesnowx Sep 26, 2024
6819c7b
Add navbar component and its styling
iynixil Sep 26, 2024
571bf9e
Update login page styling
iynixil Sep 26, 2024
71dd534
Merge branch 'user-login' into frontend-navbar
iynixil Sep 26, 2024
bac17dd
Update navbar content
iynixil Sep 26, 2024
c54e841
Update login page to use navbar
iynixil Sep 26, 2024
1572767
Merge branch 'question_branch' into question-branch-tsu
tsulim Sep 26, 2024
f8c105d
Add edit functionality
whitesnowx Sep 26, 2024
2c637f4
add server side path for edit
whitesnowx Sep 26, 2024
22be495
Merge pull request #12 from iynixil/user-login
iynixil Sep 26, 2024
616808e
Merge pull request #11 from whitesnowx/question-service
whitesnowx Sep 26, 2024
ec62853
include delete functionality
whitesnowx Sep 26, 2024
166b041
Merge pull request #13 from whitesnowx/question-service
whitesnowx Sep 26, 2024
aed4359
Merge pull request #7 from CS3219-AY2425S1/user-service-xy
AndrewOng2066 Sep 26, 2024
df7f20f
Move Signup.js and SignupValidation.js to user-service directory
Sep 26, 2024
530ebe2
Update the path after moving the Signup.js and SignupValidation.js to
Sep 26, 2024
5716310
format and styling for action buttons
whitesnowx Sep 26, 2024
c011bdb
Merge pull request #14 from whitesnowx/question-service
whitesnowx Sep 26, 2024
7881264
Update the UI for register page
Sep 26, 2024
f6bc558
Change the requirement of the password to at least 3 characters
Sep 26, 2024
e640f41
Add API to retrieve question by id
tsulim Sep 27, 2024
060f099
Add route for viewing question details
tsulim Sep 27, 2024
766454e
Add in link from home to individual question
tsulim Sep 27, 2024
11cf62b
Update navbar styling
iynixil Sep 27, 2024
c94d6f3
Extracted the backend code for the user service to
Sep 27, 2024
f726521
Merge pull request #16 from AndrewOng2066/register_user_extract
AndrewOng2066 Sep 27, 2024
8e721cd
Rename file from View.js to QuestionPage.js
tsulim Sep 27, 2024
dc788a6
Merge branch 'test-user-login-2' into frontend-navbar
iynixil Sep 28, 2024
9f3f628
add button to return to add question view
whitesnowx Sep 28, 2024
5f2a5fa
Merge pull request #17 from whitesnowx/question-service
whitesnowx Sep 28, 2024
42c27ec
Update gitignore to include vsc files
iynixil Sep 28, 2024
10e18cd
Update navbar component and styling
iynixil Sep 28, 2024
d26d287
Create component for restricting logged-in user access to pages
iynixil Sep 28, 2024
fea929f
Update login component in frontend
iynixil Sep 28, 2024
6eafa04
Create logout component used in navbar
iynixil Sep 28, 2024
3fc75d4
Update App routing
iynixil Sep 28, 2024
150f0be
Update indentations in multiple files to fit coding standard
iynixil Sep 28, 2024
ea4638a
Merge pull request #18 from iynixil/frontend-navbar
iynixil Sep 28, 2024
9e15531
Add css to question page
tsulim Sep 28, 2024
a49eab3
Add back navigation to question page
tsulim Sep 28, 2024
fb45227
Update error page
tsulim Sep 28, 2024
0adcf8b
Add loading animation for question page
tsulim Sep 28, 2024
2bfd3eb
Update css
tsulim Sep 28, 2024
8757cac
Merge pull request #8 from CS3219-AY2425S1/user-service-xy
AndrewOng2066 Sep 29, 2024
46f2a59
Add NavBar and remove unnecessary texts in Signup.js
Sep 29, 2024
8cf50b7
Merge pull request #21 from AndrewOng2066/main2
AndrewOng2066 Sep 29, 2024
04e8fc0
Add component for Error404
tsulim Sep 29, 2024
72787fd
Update usage of error page
tsulim Sep 29, 2024
6f86328
Extract out firebase configuration from `index.js` to `firebase.js`
tsulim Sep 29, 2024
9e9985a
Merge pull request #19 from CS3219-AY2425S1/question-branch-cal
tsulim Sep 29, 2024
8701d7d
Merge remote-tracking branch 'upstream/question_branch' into question…
tsulim Sep 29, 2024
24917d7
Fix bug in `firebase.js`
tsulim Sep 29, 2024
73986d6
Update css
tsulim Sep 29, 2024
62e9a55
Merge pull request #20 from CS3219-AY2425S1/question-branch-tsu
whitesnowx Sep 29, 2024
97042a0
Add scroll back to top for edit button
xuelinglow Sep 29, 2024
fdb2f3d
Make complexity start with capital letter
xuelinglow Sep 29, 2024
a3b42c4
Merge pull request #22 from CS3219-AY2425S1/question_branch_xl
tsulim Sep 29, 2024
26d7959
Handle duplicate title
xuelinglow Sep 29, 2024
4c56393
Add loading to main page
xuelinglow Sep 29, 2024
aeb80e0
Merge pull request #23 from CS3219-AY2425S1/question_branch_xl
whitesnowx Sep 29, 2024
856891c
Check for whitespaces and make changes to duplicate title checking
xuelinglow Sep 29, 2024
fe9516b
Update `class` to `className`
tsulim Sep 29, 2024
eef6380
Extract route for get question by id
tsulim Sep 29, 2024
f2f08a4
Merge remote-tracking branch 'upstream/question_branch' into question…
tsulim Sep 29, 2024
152b26c
Extract route for get all questions
tsulim Sep 29, 2024
30b5daf
Extract route for create question
tsulim Sep 29, 2024
725b3d4
Extract route for update question
tsulim Sep 29, 2024
e7c2e40
Extract route for delete question
tsulim Sep 29, 2024
50069b6
Add loading animation for update and delete
tsulim Sep 29, 2024
9cbfdc5
Remove redundant parameter
tsulim Sep 29, 2024
321cfa2
Merge pull request #27 from CS3219-AY2425S1/question-branch-tsu
iynixil Sep 30, 2024
9b205e6
Merge pull request #32 from iynixil/user-service
iynixil Sep 30, 2024
f1037de
Merge remote-tracking branch 'upstream/question_branch' into merge-us…
iynixil Oct 1, 2024
2baf086
Refactor backend directory by separating microservices
iynixil Oct 1, 2024
7035358
Update file used to configure database
iynixil Oct 1, 2024
dc5fa5d
Update backend npm cmd to use nodemon
iynixil Oct 1, 2024
cde087b
Rename frontend directory, refactor pages separated by microservices
iynixil Oct 1, 2024
18cb036
Merge pull request #33 from iynixil/merge-user-question
iynixil Oct 2, 2024
fd9fdcd
Shift remaining files into both services
tsulim Oct 4, 2024
33546ea
Merge pull request #35 from tsulim/merged-user-question
tsulim Oct 4, 2024
4194af1
Update controller files on firebase directory
tsulim Oct 4, 2024
d4cb3ab
Add Dockerfile for question service
tsulim Oct 4, 2024
77df819
Add Dockerfile for user service
tsulim Oct 4, 2024
32c0972
Add docker-compose file
tsulim Oct 4, 2024
9b2ad21
Merge branch 'merged-user-question' of https://github.com/CS3219-AY24…
tsulim Oct 4, 2024
3217fd9
Change port for user service in frontend
tsulim Oct 4, 2024
d9d8994
Update docker-compose
tsulim Oct 4, 2024
400b094
Update docker-compose
tsulim Oct 4, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.env
.env
.vscode/
14 changes: 0 additions & 14 deletions backend/firebaseConfig.js

This file was deleted.

57 changes: 0 additions & 57 deletions backend/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions backend/question-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
20 changes: 20 additions & 0 deletions backend/question-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install any dependencies
RUN npm install

# Bundle app source inside the Docker image
COPY . .

# Make port 5000 available to the world outside this container
EXPOSE 5000

# Define the command to run your app
CMD ["npm", "start"]
146 changes: 146 additions & 0 deletions backend/question-service/controller/questionController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Author(s): Calista, Xiu Jia, Xue Ling
const db = require("../db/firebase");
const questionCollection = db.collection("questions");

/**
* POST /add
*
* Creates questions from form data and store in firebase
*
* Responses:
* - 500: Server error if something goes wrong while fetching data.
*/
const createQuestion = async (req, res) => {
try {
console.log(req.body);
const questionJson = {
title: req.body.title.trim(),
category: req.body.category,
complexity: req.body.complexity,
description: req.body.description,
};

const querySnap = await questionCollection.where('title', '==', req.body.title.trim()).get();
if (!querySnap.empty) {
return res.status(409).json({ message: 'Duplicate entry found' });
}

const response = questionCollection.doc().set(questionJson); // Added 'await'
res.send({ message: "Question created successfully", response });
} catch (error) {
res.status(500).send({ error: error.message });
}
}

/**
* GET /question/
*
* Retrieves data from firebase from questions collection.
*
* Responses:
* - 200: Returns an array of data matching the query parameters.
* - 500: Server error if something goes wrong while fetching data.
*/
const getAllQuestions = async (req, res) => {
try {
const questions = await questionCollection.get();

const questionArray = [];

if (questions.empty) {
res.status(400).send("No questions found.");
}

questions.forEach((doc) => {
questionArray.push({ id: doc.id, ...doc.data() });
});

res.status(200).json(questionArray);
} catch (error) {
console.error("Error fetching data from Firebase:", error);
res.status(500).json({ message: "Error fetching data from Firebase" });
}
};

/**
* GET /question/<questionId>
*
* Retrieves specified question from questions collection in firebase.
*
* Responses:
* - 200: Returns data matching the questionId.
* - 500: Server error if something goes wrong while fetching data.
*/
const getQuestionById = async (req, res) => {
try {
const id = req.params.questionId;
const question = questionCollection.doc(id);
const data = await question.get();

if (!data.exists) {
return res.status(404).send({ message: "Question not found" });
}

res.status(200).send(data.data());
} catch (error) {
res.status(500).send({ error: error.message });
}
}

/**
* PUT /question/update/<questionId>
*
* Updates specified question from questions collection in firebase.
*/
const updateQuestion = async (req, res) => {
try {
const questionId = req.params.questionId;
console.log("Updating question ID:", questionId);

const updatedQuestion = {
title: req.body.title.trim(),
category: req.body.category,
complexity: req.body.complexity,
description: req.body.description,
};
const querySnap = await questionCollection.where('title', '==', req.body.title.trim()).get();
if (!querySnap.empty) {
for (const doc of querySnap.docs) {
if (doc.id != questionId) {
return res.status(409).json({ message: 'Duplicate entry found' });
}
}
}
const response = await questionCollection.doc(questionId).set(updatedQuestion, { merge: true });

res.send({ message: "Question updated successfully", response });
} catch (error) {
console.log(error.message)
res.status(500).send({ error: error.message });
}
}

/**
* DELETE /question/delete/<questionId>
*
* Deletes specified question from questions collection in firebase.
*/
const deleteQuestion = async (req, res) => {
try {
const questionId = req.params.questionId;
console.log("Deleting question ID:", questionId);

await questionCollection.doc(questionId).delete();

res.send({ message: "Question deleted successfully" });
} catch (error) {
res.status(500).send({ error: error.message });
}
}

module.exports = { createQuestion,
getAllQuestions,
getQuestionById,
updateQuestion,
deleteQuestion
};
24 changes: 24 additions & 0 deletions backend/question-service/db/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Author(s): Andrew, Xiu Jia
require("dotenv").config();
const admin = require("firebase-admin");

const firebaseConfig = {
type: "service_account",
project_id: "cs3219-d4ee1",
private_key_id: "d9899e20a23a397cdce523437f42d50696aede61",
private_key: process.env.PRIVATE_KEY,
client_email: "firebase-adminsdk-hba0d@cs3219-d4ee1.iam.gserviceaccount.com",
client_id: "106098472779235960036",
auth_uri: "https://accounts.google.com/o/oauth2/auth",
token_uri: "https://oauth2.googleapis.com/token",
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
client_x509_cert_url: "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-hba0d%40cs3219-d4ee1.iam.gserviceaccount.com",
universe_domain: "googleapis.com"
};

admin.initializeApp({
credential: admin.credential.cert(firebaseConfig)
});
const db = admin.firestore();

module.exports = db;
22 changes: 22 additions & 0 deletions backend/question-service/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Author(s): Andrew, Calista, Xinyi, Xiu Jia, Xue Ling
require("dotenv").config();

const express = require("express");
const cors = require("cors");
const app = express();
const port = process.env.PORT;

const questionRoute = require("./routes/questionRoute");

app.use(cors());
app.use(express.json());

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Routes
app.use("/question", questionRoute);

app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
"start": "nodemon index.js"
},
"author": "",
"license": "ISC",
Expand Down
19 changes: 19 additions & 0 deletions backend/question-service/routes/questionRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Author(s): Calista, Xiu Jia, Xue Ling
const express = require("express");
const router = express.Router();

const {
createQuestion,
getAllQuestions,
getQuestionById,
updateQuestion,
deleteQuestion
} = require("../controller/questionController");

router.get("/", getAllQuestions);
router.get("/:questionId", getQuestionById);
router.post("/add", createQuestion);
router.put("/update/:questionId", updateQuestion);
router.delete("/delete/:questionId", deleteQuestion);

module.exports = router;
2 changes: 2 additions & 0 deletions backend/user-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
20 changes: 20 additions & 0 deletions backend/user-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install any dependencies
RUN npm install

# Bundle app source inside the Docker image
COPY . .

# Make port 5001 available to the world outside this container
EXPOSE 5001

# Define the command to run your app
CMD ["npm", "start"]
Loading