diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d6c6e49..25b05d8 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -14,9 +14,9 @@
-
+
-
+
@@ -210,7 +210,10 @@
-
+
+
+
+
1713528225837
@@ -392,7 +395,15 @@
1716977853269
-
+
+
+ 1716988959836
+
+
+
+ 1716988959836
+
+
@@ -433,6 +444,7 @@
-
+
+
\ No newline at end of file
diff --git a/code/server/incoming_request_handlers.js b/code/server/incoming_request_handlers.js
index 6fa0f41..ef583a1 100644
--- a/code/server/incoming_request_handlers.js
+++ b/code/server/incoming_request_handlers.js
@@ -1,3 +1,6 @@
+
+const databaseQuery = 'SELECT * FROM `Exercise` ORDER BY RAND() LIMIT 1';
+
/**
*
* @param {Request} request The incoming request
@@ -8,45 +11,33 @@
function handleIncoming(request, response, app, pool)
{
- let query = 'SELECT * FROM Exercise WHERE ExerciseID = ?';
- let parameters = [];
-
- if (!request.hasOwnProperty('uid') || typeof request.uid !== 'number')
- {
- query = 'SELECT * FROM Exercise ORDER BY RAND() LIMIT 1';
- } else parameters.push(request.uid);
-
// Acquire database connection
pool.getConnection()
.then(conn => {
- conn.query(query, parameters)
+ conn.query(
+ databaseQuery)
.then(rows => {
if (rows.length === 0)
{
response
.status(404)
- .send(JSON.stringify({error: 'Exercise not found'}));
+ .send(JSON.stringify({error: 'No exercises found in the database.'}));
}
else
{
- // Send back the data in the right format
- let converted = rows.map(row => {
- return {
- exerciseId: row.ExerciseID,
- name: row.Name,
- muscleGroup: row.MuscleGroup,
- shortDescription: row.ShortDescription,
- description: row.Description,
- imageUrl: row.ImageURL,
- videoUrl: row.VideoURL,
- path: row.Path,
- duration: row.Duration
- };
- })[0];
-
- response
- .status(200)
- .send(JSON.stringify(converted));
+ let row = rows[0];
+ response.status(200)
+ .send(JSON.stringify({
+ exerciseId: row['ExerciseID'],
+ name: row['Name'],
+ muscleGroup: row['MuscleGroup'],
+ shortDescription: row['ShortDescription'],
+ description: row['Description'],
+ imageUrl: row['ImageURL'],
+ videoUrl: row['VideoURL'],
+ path: row['Path'],
+ duration: row['Duration']
+ }))
}
})
.catch(error => {