From 8047ba1650f99ac926506dff0f336c0f9b860bcc Mon Sep 17 00:00:00 2001
From: Sami Spets <savasp@utu.fi>
Date: Tue, 8 Oct 2019 12:57:11 +0300
Subject: [PATCH] changes to GET /stream/config route

---
 web-service/server/public/js/index.js    |  6 ++++--
 web-service/server/src/index.js          | 18 ++++++++++++------
 web-service/server/src/models/configs.js |  3 +--
 web-service/server/src/utils/config.js   |  5 +----
 4 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/web-service/server/public/js/index.js b/web-service/server/public/js/index.js
index ab33359bb..209b38ef4 100644
--- a/web-service/server/public/js/index.js
+++ b/web-service/server/public/js/index.js
@@ -7,13 +7,15 @@ const checkIfLoggedIn = async () => {
         containerDiv = login;
     //User has a token saved in the browser
     }else{
-        //validate that token
+
+        //Check if the token is valid
         const response = await fetch('http://localhost:8080/auth/validation', {
             method: 'POST',
             headers: {'Authorization': token}
         })
         console.log('RESPONSE', response)
-        //Token is valid
+        
+        //Token is valid, show the streams
         if(response.status === 200){
             console.log("SUCCESS")
             /*
diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js
index 43205eaec..49a9d78db 100644
--- a/web-service/server/src/index.js
+++ b/web-service/server/src/index.js
@@ -170,8 +170,8 @@ app.post('/auth/validation', async (req, res) => {
 		console.log(err)
 	}	
 })
-// app.get('/login/google', (req, res) => {
-// })
+
+
 
 
 app.get('/streams', (req, res) => {
@@ -204,13 +204,14 @@ app.get('/stream/depth', (req, res) => {
 });
 
 app.post('/stream/config', async (req, res) => {
-	const {board_size, square_size, frame_delay, num_frames} = req.body
+	const {board_size, square_size, frame_delay, num_frames, name} = req.body
 
 	const savedConfigs = new Config({
 		board_size,
 		square_size,
 		frame_delay,
 		num_frames,
+		name
 	});
 	try{
 		await savedConfigs.save();
@@ -222,9 +223,13 @@ app.post('/stream/config', async (req, res) => {
 })
 
 app.get('/stream/config', async(req, res) => {
-	const listOfCongifs = await Config.find({});
-	console.log(listOfCongifs)
-	return res.status(200).json(listOfCongifs)
+	//example of uri /stream/config?uri=ftl.utu.fi/stream/calibrations/
+	//example of uri /stream/config?uri=ftl.utu.fi/stream/calibrations/board_size/value=1
+	const uri = req.query.uri
+	console.log(uri)
+
+	//const listOfCongifs = await Config.find({});
+	return res.status(200).json(uri)
 })
 
 //app.get('/stream', (req, res))
@@ -283,6 +288,7 @@ app.get('/auth/google/redirect', passport.authenticate('google'), async (req, re
 		return res.send(htmlWithEmbeddedJWT)
 	}catch(err){
 		console.log(err)
+		return res.status(500).json('Login failed')
 	}
 })
 
diff --git a/web-service/server/src/models/configs.js b/web-service/server/src/models/configs.js
index b15dd2db4..ff617d61f 100644
--- a/web-service/server/src/models/configs.js
+++ b/web-service/server/src/models/configs.js
@@ -14,7 +14,7 @@ const cameraConfigSchema = mongoose.Schema({
     fix_k3: {type: Boolean, default: false},
     fix_k4: {type: Boolean, default: true},
     fix_k5: {type: Boolean, default: true},
-    //Mongoose doesn't let you use 'save' as an attribute
+    //Mongoose doesn't let you use the word 'save' as an attribute
     //save: {type: Boolean, default: true},
     use_intrinsics: {type: Boolean, default: true},
     use_extrinsics: {type: Boolean, default: true},
@@ -25,7 +25,6 @@ const cameraConfigSchema = mongoose.Schema({
 
   cameraConfigSchema.set('toJSON', {
     transform: (document, returnedObject) => {
-      returnedObject.id = returnedObject._id
       delete returnedObject._id
       delete returnedObject.__v
     }
diff --git a/web-service/server/src/utils/config.js b/web-service/server/src/utils/config.js
index d1ec0b035..99f9a002b 100644
--- a/web-service/server/src/utils/config.js
+++ b/web-service/server/src/utils/config.js
@@ -1,6 +1,3 @@
-
-const MONGODB_URI = 'mongodb+srv://ftl:sOgIX%2638@FTL-w141e.mongodb.net/FTL?retryWrites=true&w=majority'
-
 module.exports = {
-    MONGODB_URI
+    MONGODB_URI: 'mongodb+srv://ftl:sOgIX%2638@FTL-w141e.mongodb.net/FTL?retryWrites=true&w=majority'
 }
\ No newline at end of file
-- 
GitLab