From d080f0af8dd353a819efe1a2931efff9aa5e01ce Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Wed, 29 May 2024 12:17:33 +0200 Subject: [PATCH] Updated incoming_request_handlers.js to match database querying --- .idea/workspace.xml | 40 +++++++++++++++++++++++---- code/web/incoming_request_handlers.js | 21 ++++++++------ code/web/pepper_data_test.js | 24 ++++++++++++++++ 3 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 code/web/pepper_data_test.js diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 691e0e6..4020532 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -14,7 +14,8 @@ - + + @@ -49,6 +50,7 @@ @@ -87,6 +89,7 @@ { "keyToString": { + "Node.js.pepper_data_test.js.executor": "Run", "git-widget-placeholder": "main", "node.js.detected.package.eslint": "true", "node.js.detected.package.tslint": "true", @@ -103,7 +106,7 @@ - + + + + + + + + + @@ -197,7 +208,9 @@ - + + + 1713528225837 @@ -355,7 +368,23 @@ - @@ -394,6 +423,7 @@ - \ No newline at end of file diff --git a/code/web/incoming_request_handlers.js b/code/web/incoming_request_handlers.js index 8289837..6049b3b 100644 --- a/code/web/incoming_request_handlers.js +++ b/code/web/incoming_request_handlers.js @@ -31,16 +31,19 @@ function handleIncoming(request, response, app, pool) else { // Send back the data in the right format - let firstRow = rows[0]; + let converted = rows.map(row => { + return { + name: row.Name, + description: row.Description, + muscleGroup: row.MuscleGroup, + imageUrl: row.ImageURL, + videoUrl: row.VideoURL + }; + }); + response .status(200) - .send(JSON.stringify({ - name: firstRow.Name, - description: firstRow.Description, - muscleGroup: firstRow.MuscleGroup, - imageUrl: firstRow.ImageURL, - videoUrl: firstRow.VideoURL - })); + .send(JSON.stringify(converted)); } }) .catch(error => { @@ -64,5 +67,5 @@ function handleIncoming(request, response, app, pool) // Export the function that registers the incoming request handlers module.exports = function(app, pool) { - app.get('/', (req, res) => handleIncoming(req, res, app, pool)); + app.post('/', (req, res) => handleIncoming(req, res, app, pool)); }; \ No newline at end of file diff --git a/code/web/pepper_data_test.js b/code/web/pepper_data_test.js new file mode 100644 index 0000000..674aa18 --- /dev/null +++ b/code/web/pepper_data_test.js @@ -0,0 +1,24 @@ +const address = 'http://145.92.8.135:3445/'; + +const data = { + rotationX: 1, + rotationY: .4, + rotationZ: .1, + accelerationX: 1, + accelerationY: 2, + accelerationZ: 4, + deviceId: 1, + type: 'data' +}; + +for ( let i = 0; i < 10; i++) +{ + setTimeout(() => { + console.log("Sending data"); + fetch(address, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data) + }); + }, i * 1000); +} \ No newline at end of file