From fdf03c2a7032685d45cd9a249356fb0b666d6023 Mon Sep 17 00:00:00 2001
From: Jijeong Lee <jijeong0114@gmail.com>
Date: Mon, 11 Dec 2023 09:55:13 -0800
Subject: [PATCH] Change return value type to string array

Reason: Javascript doesn't have sorted map data structure. We need to send the response value in sorted list.
---
 emission/core/wrapper/user.py  | 4 ++--
 emission/net/api/cfc_webapp.py | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/emission/core/wrapper/user.py b/emission/core/wrapper/user.py
index 45c491958..1120bbac8 100644
--- a/emission/core/wrapper/user.py
+++ b/emission/core/wrapper/user.py
@@ -234,7 +234,7 @@ def getModes(self):
     modes = user['modes']
     filteredModes = {key: value for key, value in modes.items() if value.get('isActive', False)}
     sortedModes = dict(sorted(filteredModes.items(), key=lambda x: (x[1]["frequency"]), reverse=True))
-    return sortedModes  
+    return list(sortedModes)  
   
   def updateModes(self, updated_mode):
     from datetime import datetime
@@ -243,7 +243,7 @@ def updateModes(self, updated_mode):
     old_mode = updated_mode['old_mode']
     new_mode = updated_mode['new_mode']
     is_new_mode_must_added = updated_mode['is_new_mode_must_added']
-    
+
     if new_mode in modes:
       updated_frequency = modes[new_mode]['frequency'] + 1
       modes[new_mode]['frequency'] = updated_frequency
diff --git a/emission/net/api/cfc_webapp.py b/emission/net/api/cfc_webapp.py
index 944684736..575034ea9 100644
--- a/emission/net/api/cfc_webapp.py
+++ b/emission/net/api/cfc_webapp.py
@@ -311,17 +311,17 @@ def getUserModes():
   logging.debug("Called getUserModes")
   user_uuid = getUUID(request)
   user = User.fromUUID(user_uuid)
-  return user.getModes()
+  return { 'modes' : user.getModes() }
 
 @post('/mode/update')
 def updateUserMode():
-  logging.debug("Called createUserMode")
+  logging.debug("Called updateUserMode")
   updated_mode = request.json['updated_mode']
   user_uuid = getUUID(request)
   user = User.fromUUID(user_uuid)
   to_return = user.updateModes(updated_mode)
   logging.debug("Successfully updated mode for user %s" % user_uuid)
-  return {"modes": to_return}
+  return { 'modes' : to_return }
 
 @post('/result/metrics/<time_type>')
 def summarize_metrics(time_type):