-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from CS3219-AY2425S1/matching-service-xy
Add matching service
- Loading branch information
Showing
28 changed files
with
4,571 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 5002 available to the world outside this container | ||
EXPOSE 5002 | ||
|
||
# Define the command to run your app | ||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "[email protected]", | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Established connection to the RabbitMQ | ||
require("dotenv").config(); | ||
const amqp = require('amqplib'); | ||
|
||
const rabbitSettings = { | ||
protocol: 'amqp', | ||
hostname: `rabbitmq` || process.env.HOSTNAME || 'localhost', | ||
port: 5672, | ||
username: 'guest', | ||
password: process.env.RABBIT_PASSWORD, | ||
vhost: '/', | ||
authMechanism: ['PLAIN', 'AMQPLAIN', 'EXTERNAL'] | ||
}; | ||
|
||
const connectToRabbitMQ = async () => { | ||
try { | ||
const conn = await amqp.connect(rabbitSettings); | ||
const channel = await conn.createChannel(); | ||
|
||
return { conn, channel }; | ||
} catch (error) { | ||
console.error('Error connecting to RabbitMQ:', error); | ||
} | ||
}; | ||
|
||
module.exports = connectToRabbitMQ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Author(s): Calista, Xiu Jia, Xue Ling | ||
const db = require("../config/firebase"); | ||
const matchCollection = db.collection("matches"); | ||
|
||
/** | ||
* POST /add | ||
* | ||
* Creates match and stores in firebase | ||
* | ||
* Responses: | ||
* - 500: Server error if something goes wrong while fetching data. | ||
*/ | ||
const createMatch = async (user1, user2) => { | ||
try { | ||
const matchJson = { | ||
user1: { | ||
email: user1.email, | ||
category: user1.topic, | ||
complexity: user1.difficultyLevel, | ||
isAny: user1.isAny | ||
}, | ||
user2: { | ||
email: user2.email, | ||
category: user2.topic, | ||
complexity: user2.difficultyLevel, | ||
isAny: user2.isAny | ||
}, | ||
datetime: new Date().toLocaleString("en-SG") | ||
}; | ||
|
||
const response = await matchCollection.doc().set(matchJson); | ||
|
||
return { status: 200, msg: "Match created successfully", response }; | ||
} catch (error) { | ||
return { status: 500, error: error.message }; | ||
} | ||
} | ||
|
||
module.exports = { | ||
createMatch | ||
}; |
Oops, something went wrong.