Exemplo n.º 1
0
    def getAllContactList(self):
        cursor = self.conn.cursor()
        query = "select L.clist_id, L.person_id, C.person_id from contact_list as L, " \
                "contacts as C where L.clist_id = C.clist_id;"
        cursor.execute(query)
        dao = UserDAO()
        result = []
        clist_id = 0
        contacts = []

        #Save the data of the cursor to be able to iterate through it multiple times later
        cursor_result = []
        for row in cursor:
            cursor_result.append(row)

        for row in cursor_result:
            if clist_id != row[0]:
                clist_id = row[0]
                owner_id = row[1]
                for row2 in cursor_result:
                    if owner_id == row2[1]:
                        contact_id = row2[2]
                        contacts.append(dao.getUserById(contact_id))
                result.append([clist_id, owner_id, contacts])
                contacts = []
        if result == []:
            return None
        return result
Exemplo n.º 2
0
    def getAllChatsAndMembers(self):
        cursor = self.conn.cursor()
        query = "select C.gchat_id, C.gchat_name, P.person_id " \
                "from group_chat as C, chat_members as M, person as P " \
                "where C.gchat_id = M.gchat_id " \
                "and P.person_id = M.person_id;"
        cursor.execute(query)
        dao = UserDAO()
        result = []
        gchat_id = 0
        members = []

        #Save the data of the cursor to be able to iterate through it multiple times later
        cursor_result = []
        for row in cursor:
            cursor_result.append(row)

        for row in cursor_result:
            if gchat_id != row[0]:
                gchat_id = row[0]
                chat_name = row[1]
                for row2 in cursor_result:
                    if chat_name == row2[1]:
                        person_id = row2[2]
                        members.append(dao.getUserById(person_id))
                result.append([gchat_id, chat_name, members])
                members = []
        if result == []:
            return None
        return result
Exemplo n.º 3
0
 def getUserById(self, user_id):
     dao = UserDAO()
     result = dao.getUserById(user_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToUserDict(result)
         return jsonify(User=mapped)
Exemplo n.º 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)
Exemplo n.º 5
0
 def getOwnerOfChat(self, gc_id):
     dao1 = GroupChatDAO()
     u_id = dao1.getOwnerOfChat(gc_id)
     dao2 = UserDAO()
     result = dao2.getUserById(u_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToUserDict(result)
         return jsonify(Owner=mapped)
Exemplo n.º 6
0
    def getAllChatMembersByChatID(self, gchat_id):
        cursor = self.conn.cursor()
        query = "select * from chat_members;"
        cursor.execute(query)

        dao = UserDAO()
        result = []
        for row in cursor:
            if row[1] == gchat_id:
                result.append(dao.getUserById(row[2]))
        if result == []:
            return None
        return result
Exemplo n.º 7
0
    def getContactsByUserID(self, user_id):
        cursor = self.conn.cursor()
        query = "select C.person_id from contact_list as L, " \
               "contacts as C where L.clist_id = C.clist_id and L.person_id = %s;"
        cursor.execute(query, (user_id, ))

        dao = UserDAO()
        result = []
        clist_id = 0
        owner_id = 0
        contacts = []
        for row in cursor:
            result.append(dao.getUserById(row[0]))
        if result == []:
            return None
        return result
Exemplo n.º 8
0
 def getContactListByID(self, clist_id):
     cursor = self.conn.cursor()
     query = "select L.clist_id, L.person_id, C.person_id from contact_list as L, " \
             "contacts as C where L.clist_id = C.clist_id and L.clist_id = %s;"
     cursor.execute(query, (clist_id, ))
     dao = UserDAO()
     result = []
     clist_id = 0
     owner_id = 0
     contacts = []
     firstPass = True
     for row in cursor:
         if firstPass:
             clist_id = row[0]
             owner_id = row[1]
         contacts.append(dao.getUserById(row[2]))
     # result.append([clist_id, owner_id, contacts])
     result.append(clist_id)
     result.append(owner_id)
     result.append(contacts)
     if result == []:
         return None
     return result