Ejemplo n.º 1
0
 def getDislikedMsgByUserId(self, user_id):
     dao = UserDAO()
     result = dao.getDislikedMsgByUserId(user_id)
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToMsgDict(r))
     return jsonify(DislikedMessages=mapped_result)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
 def getAllUser(self):
     dao = UserDAO()
     result = dao.getAllUser()
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToUserDict(r))
     return jsonify(User=mapped_result)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def getEmailByUserId(self, user_id):
     dao = UserDAO()
     result = dao.getEmailByUserId(user_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToEmailDict(result)
         return jsonify(Email=mapped)
Ejemplo n.º 6
0
 def getUserByUsername(self, username):
     dao = UserDAO()
     result = dao.getUserByUsername(username)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToUserDict(result)
         return jsonify(User=mapped)
Ejemplo n.º 7
0
 def getPasswordByUserId(self, user_id):
     dao = UserDAO()
     result = dao.getPasswordByUserId(user_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToPasswordDict(result)
         return jsonify(Password=mapped)
Ejemplo n.º 8
0
 def getLNameByUserId(self, user_id):
     dao = UserDAO()
     result = dao.getLNameByUserId(user_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToLNameDict(result)
         return jsonify(LastName=mapped)
Ejemplo n.º 9
0
 def deleteUser(self, form):
     if len(form) != 1:
         return jsonify(Error="Malformed post request"), 400
     else:
         person_id = form['person_id']
         if person_id:
             dao = UserDAO()
             dao.deleteUser(person_id)
             return jsonify(DeleteStatus="OK"), 200
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
 def getUserByUsernameAndPassword(self, form):
     if len(form) != 2:
         return jsonify(Error="Malformed post request"), 400
     username = form['username']
     password = form['password']
     if not username or not password:
         return jsonify(Error="Unexpected attributes in post request"), 400
     dao = UserDAO()
     result = dao.getUserByUsernameAndPassword(username, password)
     return jsonify(User=self.mapToUserDict(result))
Ejemplo n.º 12
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)
Ejemplo n.º 13
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
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def insertContact(self, form):
     if len(form) != 2:
         return jsonify(Error="Malformed post request"), 400
     else:
         owner_id = form['owner_id']
         username = form['username']
         if owner_id and username:
             dao1 = UserDAO()
             person_id = dao1.getUserByUsername(username)[0]
             if not person_id:
                 return jsonify(ERROR="NOT FOUND"), 404
             dao2 = ContactListDAO()
             result = dao2.insertContact(owner_id, person_id)
             return jsonify(Contact=self.mapToContactDict(result)), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
 def insertUser(self, form):
     if len(form) != 6:
         return jsonify(Error="Malformed post request"), 400
     else:
         first_name = form['first_name']
         last_name = form['last_name']
         email = form['email']
         phone = form['phone']
         password = form['password']
         username = form['username']
         if first_name and last_name and email and phone and password and username:
             dao = UserDAO()
             u_id = dao.insertUser(first_name, last_name, email, phone,
                                   password, username)
             ContactListDAO().insertContactList(u_id)
             result = self.mapToUserDict([
                 u_id, first_name, last_name, email, phone, password,
                 username
             ])
             return jsonify(User=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Ejemplo n.º 18
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