Beispiel #1
0
 def removeContact(self, owner, contact):
     result = ContactDAO()
     if not result.getContactByID(owner, contact):
         return jsonify(Error="Contact not found."), 404
     else:
         result.delete(owner, contact)
         return jsonify(DeleteStatus="OK"), 200
Beispiel #2
0
 def getMyContacts(self, pid):
     dao = ContactDAO()
     result = dao.getMyContactsINFO(pid)
     mapped_results = []
     for c in result:
         mapped_results.append(self.map_to_contact_info(c))
     return jsonify(My_contacts=mapped_results)
Beispiel #3
0
 def delete(self, pid, contact_id):
     dao = ContactDAO()
     if not dao.getMyContactByid(pid, contact_id):
         return jsonify(Error="User not found."), 404
     else:
         dao.delete(pid, contact_id)
         return jsonify(DeleteStatus="OK"), 200
Beispiel #4
0
 def getContactById(self, pid, contact_id):
     dao = ContactDAO()
     row = dao.getContactByid(pid, contact_id)
     if not row:
         return jsonify(Error="Contact Not Found"), 404
     else:
         user = self.map_to_contact_info(row)
         return jsonify(Contact=user)
Beispiel #5
0
    def getAllContacts(self):
        dao = ContactDAO()

        result = dao.getAllContactRelations()
        mapped_result = []
        for r in result:
            usersPair = self.searchUserDAO(r)
            mapped_result.append(self.mapToDict(usersPair))
        return jsonify(Contacts=mapped_result)
Beispiel #6
0
    def getContactsOfPerson(self, pid):
        dao = ContactDAO()
        person_list = dao.getContactsOfPerson(pid)
        result_list = []
        for row in person_list:
            result = self.buildContactDict(row)
            result_list.append(result)

        return jsonify(Contacts=result_list), 200
Beispiel #7
0
 def getContactsByUserID(self, id):
     dao = ContactDAO()
     result = dao.getContactsByUserId(id)
     print(result)
     if result == None:
         return jsonify(Error="CONTACT NOT FOUND")
     else:
         mapped_result = []
         for r in result:
             usersPair = self.searchUserDAO(r)
             print(usersPair)
             mapped_result.append(self.mapToDict(usersPair))
         if mapped_result == []:
             return jsonify(Error="USER HAS NO CONTACT")
         # mapped = self.mapToDict(usersPair)
         return jsonify(Contact=mapped_result)
Beispiel #8
0
 def getUserContacts(self, usrID):  #needs to be evaluated
     result = ContactDAO().getUserContacts(usrID)
     contacts = []
     if result:
         for r in result:
             contacts.append(self.arrangeContacts(r))
         return jsonify(Contacts=contacts)
     return jsonify(ERROR='No Contact List for the User')
Beispiel #9
0
 def getContactListbyUser(self, usrID):
     result = ContactDAO().getContactListByUser(usrID)
     if not result:
         return jsonify(ERROR='No contact list found')
     contacts = []
     for r in result:
         contacts.append(self.buildContactsByUser(r))
     return jsonify(Contacts=contacts)
Beispiel #10
0
 def getContactLists(self):
     result = ContactDAO().getContactLists()
     if not result:
         return jsonify(ERROR='No contact list found')
     contact = []
     for r in result:
         contact.append(self.buildContactList(r))
     return jsonify(ContactList=contact)
Beispiel #11
0
    def insertContact(self, pid, json):
        if len(json) != 1:
            return jsonify(Error="Malformed post request"), 400
        else:
            info = json['info']
            if info:
                user_dao = UserDAO()
                if user_dao.getUserByPhone(info):
                    contact_id = user_dao.getUserByPhone(info)[0]
                elif user_dao.getUserByEmail(info):
                    contact_id = user_dao.getUserByEmail(info)[0]
                else:
                    return jsonify(Error="User was not found"), 400

                contact_dao = ContactDAO()
                exist = contact_dao.checkIsContact(pid, contact_id)
                if not exist:
                    pid = contact_dao.addContact(pid, contact_id)
                    result = self.map_contact_attributes(pid, contact_id)
                    return jsonify(new_Contact=result), 201
                else:
                    return jsonify(Error="User is already in your contact list"), 400
            else:
                return jsonify(Error="Unexpected attributes in post request"), 400
Beispiel #12
0
 def addContactByEmail(self, form, usrID):
     print("form: ", form)
     if len(form) != 3:
         return jsonify(Error="Malformed post request"), 400
     else:
         firstname = (form.to_dict().values()[0])
         lastname = form.to_dict().values()[1]
         email = form.to_dict().values()[2]
         if firstname and lastname and email:
             contact = ContactDAO().addContactByEmail(
                 usrID, firstname, lastname, email)
             if contact:
                 result = self.buildContactAlpha(contact)
                 return jsonify(Contact=result)
             else:
                 return jsonify(ERROR='Error adding contact')
Beispiel #13
0
 def addContactJSON(self, json, usrID):
     if len(json) != 4:
         return jsonify(Error="Malformed post request"), 400
     else:
         firstname = json['first_name']
         lastname = json['last_name']
         email = json['uemail']
         phone = json['uphone']
         if firstname and lastname and phone or email:
             contact = ContactDAO().addContact(usrID, firstname, lastname,
                                               phone, email)
             if contact:
                 result = self.buildContactAlpha(contact)
                 return jsonify(Contact=result)
             else:
                 return jsonify(ERROR='Error adding contact')
Beispiel #14
0
 def getAllContacts(self):
     result = ContactDAO()
     return jsonify(result.getAllContacts())