예제 #1
0
 def getAllReplies(self):
     dao = ReplyDAO()
     result = dao.getAllReplies()
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToDict(r))
     return jsonify(Replies=mapped_result)
예제 #2
0
    def getAllReplies(self):

        replyDAO = ReplyDAO()
        dao1 = MessageDAO()
        dao2 = MessageDAO()
        sentDAO = SentDAO()
        messagesDAO = MessagesDAO()

        result = replyDAO.getAllReplies()  # get all messages that are replies
        mapped_result = []  #store all replies mapped

        for r in result:

            reply_info = []

            owner_message = dao1.getMessageById(r[0])  # original message info
            reply_message = dao2.getMessageById(r[1])  # reply message info

            reply_info.append(reply_message[1])  # append reply text
            reply_info.append(owner_message[1])  # append original message

            replyer_name = sentDAO.getUserByMessageId(
                reply_message[0])  # get replyer name
            reply_info.append(replyer_name[1] + ' ' +
                              replyer_name[2])  # append name

            chat_name = messagesDAO.getChatByMessageId(
                r[0])  # what group was the reply sent
            reply_info.append(chat_name[1])  # append group chat name

            reply_info.append(reply_message[2])  # append reply_date
            reply_info.append(owner_message[2])  # append original_message_date

            mapped_result.append(self.mapToDict(reply_info))
        return jsonify(Replies=mapped_result)
예제 #3
0
    def getAllReplies(self):
        dao = ReplyDAO()
        dao1 = MessageDAO()
        dao2 = MessageDAO()
        userDAO = UserDAO()
        chatDAO = ChatDAO()
        result = dao.getAllReplies()
        mapped_result = []
        for r in result:
            reply_info = []
            result1 = dao1.getMessageById(r[0])  # array de mensaje-reply
            result2 = dao2.getMessageById(r[1])  # array de mensaje original
            reply_info.append(result1[1]) #replyer_text
            reply_info.append(result2[1]) #original_text
            # buscar user con user id
            # result1[3] - replyer_id
            replyer = userDAO.getUserById(result1[3])

            reply_info.append(replyer[1] + ' ' +replyer[2])

            # buscar chat con chat id
            # result1[4] - chat_id
            chat_name = chatDAO.getChatById(result1[4])
            reply_info.append(chat_name[1])

            reply_info.append(result1[2]) #reply_date
            reply_info.append(result2[2]) #original_message_date

            mapped_result.append(self.mapToDict(reply_info))
        return jsonify(Replies=mapped_result)
예제 #4
0
 def getReplyByID(self, id):
     dao = ReplyDAO()
     result = dao.getReplyById(id)
     if result == None:
         return jsonify(Error="REPLY NOT FOUND")
     else:
         mapped = self.mapToDict2(result)
         return jsonify(Reply=mapped)
예제 #5
0
 def findByOwnerID(self, user_id):
     dao = ReplyDAO()
     result = dao.searchByOwnerId(user_id)
     if result == None:
         return jsonify(Error="OWNER NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             mapped_result.append(self.mapToDict(r))
         return jsonify(Replies=mapped_result)
예제 #6
0
 def findMessagesReplies(self, message_id):
     dao = ReplyDAO()
     result = dao.findReplyByMessageId(message_id)
     if result == None:
         return jsonify(Error="MESSAGE NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             mapped_result.append(self.mapToDict(r))
         return jsonify(Replies=mapped_result)
예제 #7
0
 def getAllReplies2(self):
     dao = ReplyDAO()
     dao1 = UserDAO()
     dao2 = MessageDAO()
     result = dao.getAllReplies()
     mapped_result = []
     for r in result:
         result1 = dao1.getUserById(r[1])
         result2 = dao2.getMessageById(r[2])
         r[1] = result1[1] + " " + result1[2]
         r[2] = result2[1]
         mapped_result.append(self.mapToDict2(r))
     return jsonify(Replies=mapped_result)
예제 #8
0
 def getReplyByID2(self, id):
     dao = ReplyDAO()
     dao1 = UserDAO()
     dao2 = MessageDAO()
     result = dao.getReplyById(id)
     if result == None:
         return jsonify(Error="REPLY NOT FOUND")
     else:
         result1 = dao1.getUserById(result[1])
         result2 = dao2.getMessageById(result[2])
         result[1] = result1[1] + " " + result1[2]
         result[2] = result2[1]
         mapped = self.mapToDict2(result)
         return jsonify(Reply=mapped)
예제 #9
0
    def reply(self, form, message_id, users_id, group_id):

        if len(form) != 1:
            return jsonify(Error="Malformed post request"), 400
        else:
            message_text = form['message_text']

            print(message_text)

            if message_text:

                dao = MessageDAO()
                sDao = SentDAO()
                mDao = MessagesDAO()
                hasDao = HasTagDAO()
                hashtagDao = HashtagDAO()
                rDAO = ReplyDAO()

                og_message_text = dao.getMessageById(message_id)
                new_message = " 'RE:" + og_message_text[1] + "' " + message_text
                original_message = new_message
                print(new_message)

                reply_id = dao.insert(
                    new_message)  # insert message to table, returns message id
                print(users_id)
                print(message_id)
                sent = sDao.insert(users_id,
                                   reply_id)  # link to user who sent message
                messages = mDao.insert(
                    reply_id,
                    group_id)  # link to which group the message was posted to
                reply = rDAO.insert(message_id, reply_id)

                # get message hashtags
                message_text.strip("#")
                for message_text in message_text.split():
                    if message_text.startswith("#"):
                        print(message_text)
                        hashtag_id = hashtagDao.insert(
                            message_text
                        )  # returns hashtag_id insert to hashtag table
                        hasDao.insert(reply_id, hashtag_id)

                result = self.reply_attributes(original_message)
                return jsonify(users=result), 201
            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400
예제 #10
0
 def findMessagesReplies2(self, message_id):
     dao = ReplyDAO()
     dao1 = UserDAO()
     dao2 = MessageDAO()
     result = dao.findReplyByMessageId(message_id)
     if result == None:
         return jsonify(Error="MESSAGE NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             result1 = dao1.getUserById(r[1])
             result2 = dao2.getMessageById(r[2])
             r[1] = result1[1] + " " + result1[2]
             r[2] = result2[1]
             mapped_result.append(self.mapToDict2(r))
         return jsonify(Replies=mapped_result)
예제 #11
0
 def findByOwnerID2(self, user_id):
     dao = ReplyDAO()
     dao1 = UserDAO()
     dao2 = MessageDAO()
     result = dao.searchByOwnerId(user_id)
     if result == None:
         return jsonify(Error="OWNER NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             result1 = dao1.getUserById(r[1])
             result2 = dao2.getMessageById(r[2])
             r[1] = result1[1] + " " + result1[2]
             r[2] = result2[1]
             mapped_result.append(self.mapToDict2(r))
         return jsonify(Replies=mapped_result)