Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Bostonian02 committed Apr 17, 2024
2 parents 5b51b9b + 968da6b commit fcafe38
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 469 deletions.
7 changes: 7 additions & 0 deletions backend/rest-test.http
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,10 @@ DELETE {{base}}/comments/{{feedbackId}}
Authorization: Bearer {{jwtToken}}

# responds 200 OK if successful

### UNIVERSITIES #####################################################

### Get list of all universities
GET {{base}}/universities

# responds 200 OK if successful
8 changes: 4 additions & 4 deletions backend/src/endpoints/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const jwtSecretKey = process.env.JWT_SECRET_KEY;

// Create a MySQL pool connection
const pool = createPool({
host: 'localhost',
user: 'root',
password: 'password',
database: 'cop4710',
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_NAME || 'cop4710',
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
Expand Down
11 changes: 7 additions & 4 deletions backend/src/endpoints/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import jwt from 'jsonwebtoken';

// Database connection setup
const dbConfig = {
host: 'localhost',
user: 'root',
password: 'password',
database: 'cop4710'
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_NAME || 'cop4710',
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
};
const pool = mysql.createPool(dbConfig);

Expand Down
9 changes: 5 additions & 4 deletions backend/src/endpoints/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ dotenv.config();

const router = express.Router();
const db = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'password',
database: 'cop4710'
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || 3306,
user: process.env.DB_USER || 'root',
password: process.env.DB_PASS || 'password',
database: process.env.DB_NAME || 'cop4710'
});
const query = promisify(db.query).bind(db);

Expand Down
8 changes: 4 additions & 4 deletions backend/src/endpoints/rsos.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ dotenv.config();

const router = express.Router();
const db = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'password',
database: 'cop4710'
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_NAME || 'cop4710'
});
const query = promisify(db.query).bind(db);

Expand Down
33 changes: 33 additions & 0 deletions backend/src/endpoints/universities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import express from 'express';
import { promisify } from 'util';
import mysql from 'mysql2';

import dotenv from 'dotenv';
dotenv.config();

const router = express.Router();
const db = mysql.createPool({
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || 3306,
user: process.env.DB_USER || 'root',
password: process.env.DB_PASS || 'password',
database: process.env.DB_NAME || 'cop4710'
});
const query = promisify(db.query).bind(db);

// Return a list of university names
router.get('/', async (req, res) => {
try {
const universities = await query('SELECT university_id, name FROM universities');
const formattedResponse = universities.map(university => ({
id: university.university_id,
name: university.name
}));
res.json(formattedResponse);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal server error' });
}
});

export default router;
2 changes: 2 additions & 0 deletions backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import authRouter from './endpoints/auth.js';
import commentsRouter from './endpoints/comments.js';
import rsosRouter from './endpoints/rsos.js';
import eventsRouter from './endpoints/events.js';
import universitiesRouter from './endpoints/universities.js';

const app = express();

Expand All @@ -20,6 +21,7 @@ app.use('/auth', authRouter);
app.use('/comments', commentsRouter);
app.use('/rsos', rsosRouter);
app.use('/events', eventsRouter);
app.use('/universities', universitiesRouter);

// Catch-all route for unhandled requests
app.use('*', (req, res) => {
Expand Down
Loading

0 comments on commit fcafe38

Please sign in to comment.