Skip to content

Commit

Permalink
Change return value type to string array
Browse files Browse the repository at this point in the history
Reason: Javascript doesn't have sorted map data structure. We need to send the response value in sorted list.
  • Loading branch information
jiji14 committed Dec 11, 2023
1 parent 42fb3b6 commit fdf03c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions emission/core/wrapper/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions emission/net/api/cfc_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fdf03c2

Please sign in to comment.