From 57f944c2c76fedb7f65e83a4a3097bbde6e4e8fc Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Thu, 2 Jul 2015 23:12:14 +0300 Subject: [PATCH] API: New Message /api/messages/getAllUserMessages/ --- SE_API/MessageRoutes.py | 92 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/SE_API/MessageRoutes.py b/SE_API/MessageRoutes.py index a181620..737cc21 100644 --- a/SE_API/MessageRoutes.py +++ b/SE_API/MessageRoutes.py @@ -194,6 +194,98 @@ def getMessagesByGroup(token, groupId): status=200, mimetype="application/json") +@message_routes.route('/api/messages/getAllUserMessages/', methods=["GET"]) +@auto.doc() +def getAllUserMessages(token): + """ + >This Call will return an array of all messages (sorted by date),
+
+
+ Route Parameters
+ - SeToken: token
+ - groupId: 1234567890 +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ [
+ {
+ 'groupId' : 1234567890,
+ 'message' : 'hello all',
+ 'date' : {
+ 'year': 2015,
+ 'month': 5,
+ 'day': 5,
+ 'hour': 5,
+ 'minute': 5
+ },
+ 'id' : 1234567890,
+ 'master_id' : 1234567890,
+ 'isProject' : false,
+ 'user': {
+ 'username': 'DarkLord',
+ 'name': 'Darth Vader',
+ 'email': 'darkLord@death.planet,
+ 'isLecturer': 'True',
+ 'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',
+ 'avatar_url': 'http://location.git.com/somthing'
+ 'isFirstLogin': False,
+ 'campuses_id_list': [43243532532,5325325325,532532342],
+ 'courses_id_list': [53523,43432423,432432432432]
+ 'id': 1234567890
+ },
+ 'group': {The Group Object Project OR Campus (according to isProject)}

+ + }
+ ]
+
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("No such User") + + arr = [] + + query = Message.all() + query.filter('isProject =', False) + for m in query.run(): + if str(m.groupId) in user.courses_id_list: + msgDic = dict(json.loads(m.to_JSON())) + #add a key 'forSortDate' for sorting dates + msgTime = datetime.datetime(msgDic['date']['year'], msgDic['date']['month'], msgDic['date']['day'], msgDic['date']['hour'], msgDic['date']['minute']) + msgDic['forSortDate'] = msgTime + arr.append(msgDic) + + query = Message.all() + query.filter('isProject =', True) + for m in query.run(): + if str(m.groupId) in user.projects_id_list: + msgDic = dict(json.loads(m.to_JSON())) + #add a key 'forSortDate' for sorting dates + msgTime = datetime.datetime(msgDic['date']['year'], msgDic['date']['month'], msgDic['date']['day'], msgDic['date']['hour'], msgDic['date']['minute']) + msgDic['forSortDate'] = msgTime + arr.append(msgDic) + + arr = sorted(arr, key=itemgetter('forSortDate'), reverse=True) + for i in arr: + del i['forSortDate'] + print arr + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return Response(response=[], + status=200, + mimetype="application/json") + #---------------------------------------------------------- # DELETE