Skip to content

Commit

Permalink
Merge pull request CS3219-AY2324S1#20 from CS3219-AY2324S1/nginx-CI
Browse files Browse the repository at this point in the history
Final Project
  • Loading branch information
MrTwit99 authored Nov 14, 2023
2 parents d16586e + b081607 commit 194dbf3
Show file tree
Hide file tree
Showing 25 changed files with 8,364 additions and 171 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI Pipeline
on:
push:
branches:
- master
- CI-Docker
- nginx-CI
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'

- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: '6.0'

- name: Install dependencies
run: npm run install-all

- name: Run Tests
run: npm run test-ci
env:
ACCESS_TOKEN_SECRET: ${{ secrets.AUTH_TOKEN }}
Binary file added G47_Report.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ay2324s1-course-assessment-g47 created by GitHub Classroom
2. [Assignment 2](#assignment-2)
3. [Assignment 3](#assignment-3)
4. [Assignment 4](#assignment-4)
5. [Assignment 5](#assignment-5)
5. [Assignment 5 and Project](#assignment-5-and-project)
6. [Setting up PostgreSQL Permissions](#setting-up-postgresql-permissions)


Expand Down Expand Up @@ -107,7 +107,7 @@ Follow these steps to run the project:
- Admin: [email protected], PW: 123456
- SuperAdmin: [email protected], PW: 123456

## Assignment 5:
## Assignment 5 and Project:
**Setup:**
Follow these steps to run the project:

Expand Down
61 changes: 52 additions & 9 deletions backend/history-service/database.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
require("dotenv").config(); // Load environment variables from .env file

//write database code
const { Pool } = require("pg");
const { newDb } = require("pg-mem");

let pool;

const pool = new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
database: process.env.DB_DATABASE, //Comment out when creating a new database
});
if (process.env.NODE_ENV === "test" || process.env.NODE_ENV === 'ci') {
// Use pg-mem for testing
const { Client } = newDb().adapters.createPg();
const pgMemDb = new Client();
pool = {
query: (text, params) => pgMemDb.query(text, params),
end: () => pgMemDb.cleanup(),
};
console.log("Connected to pg-mem for testing");
} else {
// Connect to the actual PostgreSQL database
pool = new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
database: process.env.DB_DATABASE,
});
console.log("Connected to PostgreSQL");
}

module.exports = pool;

Expand Down Expand Up @@ -77,3 +91,32 @@ module.exports = pool;
// });

// module.exports = pool;

// Create the code_attempts table if it doesn't exist
const createCodeAttemptsTableQuery = `
CREATE TABLE IF NOT EXISTS code_attempts (
attempt_id serial PRIMARY KEY,
user1_email VARCHAR(255) NOT NULL,
user2_email VARCHAR(255) NOT NULL,
room_id VARCHAR(255) NOT NULL,
timestamp VARCHAR ( 255 ) NOT NULL,
language VARCHAR(255) NOT NULL,
question_name VARCHAR(255) NOT NULL,
question_difficulty VARCHAR(255) NOT NULL,
question_category VARCHAR(255) NOT NULL,
question_created_timestamp TIMESTAMP NOT NULL,
question_updated_timestamp TIMESTAMP NOT NULL,
code TEXT NOT NULL,
question_description TEXT NOT NULL
);
`;

pool.query(createCodeAttemptsTableQuery)
.then((res) => {
console.log("Code attempts table created or already exists.");
})
.catch((err) => {
console.error("Error creating code attempts table:", err);
});

module.exports = pool;
10 changes: 9 additions & 1 deletion backend/history-service/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ require("dotenv").config();
const express = require("express");
const cors = require("cors");
const pool = require("./database");
const historyPort = process.env.HISTORYPORT || 8085;
let historyPort;

if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'ci') {
historyPort = 8093;
} else {
historyPort = process.env.HISTORYPORT || 8085;
}

const appForHistory = express();

Expand Down Expand Up @@ -73,3 +79,5 @@ appForHistory.post("/api/history/manage-code-attempt", async (req, res) => {
appForHistory.listen(historyPort, () => {
console.log(`History service running on port ${historyPort}`);
});

module.exports = appForHistory;
Loading

0 comments on commit 194dbf3

Please sign in to comment.