示例#1
0
 def getAllMsgByUserId(self, user_id):
     dao = MsgDAO()
     result = dao.getAllMsgByUserId(user_id)
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToMsgDict(r))
     return jsonify(Message=mapped_result)
示例#2
0
 def getAllMsg(self):
     dao = MsgDAO()
     result = dao.getAllMsg()
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToMsgDict(r))
     return jsonify(Message=mapped_result)
示例#3
0
 def getTextByMsgId(self, msg_id):
     dao = MsgDAO()
     result = dao.getTextByMsgID(msg_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToTextDict(result)
         return jsonify(Message=mapped)
示例#4
0
 def getAuthorByMsgId(self, msg_id):
     dao = MsgDAO()
     result_id = dao.getAuthorByMsgId(msg_id)
     if result_id == None:
         return jsonify(Error="NOT FOUND"), 404
     userDao = UserDAO()
     result = userDao.getUserById(result_id[0])
     mapped = self.mapToUserDict(result)
     return jsonify(Author=mapped)
示例#5
0
 def deleteMsg(self, form):
     if len(form) != 1:
         return jsonify(Error="Malformed post request"), 400
     else:
         msg_id = form['msg_id']
         if msg_id:
             dao = MsgDAO()
             dao.deleteMsg(msg_id)
             return jsonify(DeleteStatus="OK"), 200
示例#6
0
 def getOriginalByReplyId(self, reply_id):
     dao = MsgDAO()
     msg_handler = MsgHandler()
     result = dao.getOriginalByReplyId(reply_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = msg_handler.mapToMsgDict(result)
         return jsonify(Original=mapped)
示例#7
0
 def getMessagesByChatIdAndUserId(self, gchat_id, user_id):
     dao = MsgDAO()
     result = dao.getMessagesByChatIdAndUserId(gchat_id, user_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToMsgDict(r))
     return jsonify(Messages=mapped_result)
示例#8
0
 def getAllDislikeUsersByMsgID(self, msg_id):
     dao = MsgDAO()
     result = dao.getAllDislikeUsersByMsgID(msg_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped_result = []
         for r in result:
             mapped_result.append(self.mapToUserDict(r))
         return jsonify(UsersThatDislike=mapped_result)
示例#9
0
 def getAllReplies(self):
     dao = MsgDAO()
     result = dao.getAllReplies()
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped_result = []
         for r in result:
             mapped_result.append(self.mapToMsgDict(r))
         return jsonify(Replies=mapped_result)
示例#10
0
 def getRepliesByOriginalId(self, original_id):
     dao = MsgDAO()
     result = dao.getRepliesByOriginalId(original_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped_result = []
         for r in result:
             mapped_result.append(self.mapToMsgDict(r))
         return jsonify(Replies=mapped_result)
示例#11
0
 def getUsersWhoDislikeMessages(self, msg_id):
     dao1 = MsgDAO()
     result = dao1.getAllDislikeUsersByMsgID(msg_id)
     if not result:
         return jsonify(Error="NOT FOUND"), 404
     dao2 = UserDAO()
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToUserDict(r))
     return jsonify(Users=mapped_result)
示例#12
0
 def insertReply(self, form):
     if len(form) != 2:
         return jsonify(Error="Malformed post request"), 400
     else:
         original_id = form['original_id']
         msg_id = form['msg_id']
         if original_id and msg_id:
             dao = MsgDAO()
             reply_id = dao.insertReply(original_id, msg_id)
             result = self.mapToReplyDict([reply_id, original_id, msg_id])
             return jsonify(Reply=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
示例#13
0
 def insertMsg(self, form):
     if len(form) != 4:
         return jsonify(Error="Malformed post request"), 400
     else:
         text = form['text']
         person_id = form['person_id']
         gchat_id = form['gchat_id']
         username = form['username']
         hashtags = [i for i in text.split() if i.startswith("#")]
         if text and person_id and gchat_id and username:
             dao = MsgDAO()
             msg = dao.insertMsg(text, 0, 0, person_id, gchat_id, username)
             result = self.mapToMsgDict(msg)
             if hashtags:
                 dao = HashtagDAO()
                 for h in hashtags:
                     dao.insertHashtag(h[1:], result['msg_id'])
             return jsonify(Message=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
示例#14
0
 def updateDisikes(self, form):
     if len(form) != 4:
         return jsonify(Error="Malformed post request"), 400
     else:
         likes = form['likes']
         dislikes = form['dislikes']
         person_id = form['person_id']
         msg_id = form['msg_id']
         if likes is not None and dislikes is not None and person_id and msg_id:
             dao = MsgDAO()
             react = dao.getReactByMsgAndUserID(msg_id, person_id)
             # If users hasn't reacted yet to message
             if not react:
                 react_id = dao.insertReact(likes, dislikes, person_id,
                                            msg_id)
                 dao.updateReactCount(0, 1, msg_id)
                 return jsonify(React=self.mapToReact(
                     [react_id, likes, dislikes, person_id, msg_id]))
             else:
                 # User already disliked message, set dislike to false
                 if react[2] == True:
                     react_id = dao.updateReact(likes, not dislikes,
                                                person_id, msg_id)
                     dao.updateReactCount(0, -1, msg_id)
                     return jsonify(React=self.mapToReact(react))
                 # User had liked message, set dislike to true and like to false
                 elif react[1] == True:
                     react_id = dao.updateReact(likes, dislikes, person_id,
                                                msg_id)
                     dao.updateReactCount(-1, 1, msg_id)
                     return jsonify(React=self.mapToReact(
                         [react_id, likes, dislikes, person_id, msg_id]))
                 else:
                     react_id = dao.updateReactCount(
                         likes, dislikes, person_id, msg_id)
                     dao.updateReactCount(0, 1, msg_id)
                     return jsonify(React=self.mapToReact(
                         [react_id, likes, dislikes, person_id, msg_id]))
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400