Ejemplo n.º 1
0
    def getAllReactions(self):
        dao = ReactionDAO()
        dao1 = MessageDAO()
        dao2 = UsersDAO()

        result = dao.getAllReactions()
        mapped_result = []
        for r in result:
            mapped_info = []
            user = dao2.getUserById(r[0])
            message = dao1.getMessageById(r[1])
            mapped_info.append(message[1])  # message text in which it reacted
            mapped_info.append(user[1] + ' ' + user[2])
            mapped_info.append(r[2])
            mapped_result.append(self.mapToDict(mapped_info))
        return jsonify(Reactions=mapped_result)
Ejemplo n.º 2
0
 def getMessageDislikesCount(self, message_id):
     dao = ReactionDAO()
     dao1 = MessageDAO()
     dao2 = UsersDAO()
     result = dao.getDislikesCountToMessageId(message_id)  # returns count
     if result == None:
         return jsonify(Error="REACTION NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             mapped_info = []
             message = dao1.getMessageById(message_id)
             mapped_info.append(
                 message[1])  # message text in which it reacted
             mapped_info.append(r[0])  # count
             mapped_result.append(self.mapToDict3(mapped_info))
         return jsonify(Reaction=mapped_result)
Ejemplo n.º 3
0
 def getReactionsByUserID(self, users_id):
     dao = ReactionDAO()
     dao1 = MessageDAO()
     dao2 = UsersDAO()
     result = dao.getReactionsByUserId(users_id)
     if result == None:
         return jsonify(Error="REACTION NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             mapped_info = []
             user = dao2.getUserById(r[0])
             message = dao1.getMessageById(r[1])
             mapped_info.append(
                 message[1])  # message text in which it reacted
             mapped_info.append(user[1] + ' ' + user[2])
             mapped_info.append(r[2])
             mapped_result.append(self.mapToDict(mapped_info))
         return jsonify(Reactions=mapped_result)
Ejemplo n.º 4
0
 def insertMessage(self, content, pid, gid):
     cursor = self.conn.cursor()
     query = "INSERT INTO messages (content, pid, gid) VALUES (%s, %s, %s)" \
             "RETURNING mid, date;"
     cursor.execute(query, (content, pid, gid))
     mid_date = cursor.fetchone()
     self.conn.commit()
     reaction_dao = ReactionDAO()
     hashtags = set(tag[1:] for tag in content.split()
                    if tag.startswith("#"))
     for tag in hashtags:
         hid = reaction_dao.getTagId(tag)
         if not hid:
             hid = reaction_dao.createHashtag(tag)
             reaction_dao.insertTag(mid_date[0], hid)
         else:
             reaction_dao.insertTag(mid_date[0], hid)
     return mid_date
Ejemplo n.º 5
0
 def dislike(self, mid, json):
     """Add a like on the message"""
     if len(json) != 1:
         return jsonify(Error="Malformed post request"), 400
     else:
         pid = json['pid']
         if pid:
             dao = ReactionDAO()
             if not dao.getWhoDislikedById(mid, pid):
                 mid = dao.insertDislike(mid, pid)
             else:
                 dao.deleteDislike(mid, pid)
             result = self.map_likes_dislikes_attributes(mid, pid)
             return jsonify(Message=result), 201
         else:
             return jsonify(Error="Unexpected attributes in post request"), 400
Ejemplo n.º 6
0
 def getMessageDislikes(self, mid):
     dao = ReactionDAO()
     dislikes = dao.getMessageDislikes(mid)
     return jsonify(Dislikes=dislikes)
Ejemplo n.º 7
0
 def getMessageLikes(self, mid):
     dao = ReactionDAO()
     likes = dao.getMessageLikes(mid)
     return jsonify(Likes=likes)