Example #1
0
 def getAllContactList(self):
     dao = ContactListDAO()
     result = dao.getAllContactList()
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToContactListDict(r))
     return jsonify(ContactLists=mapped_result)
Example #2
0
 def getContactListByID(self, clist_id):
     dao = ContactListDAO()
     result = dao.getContactListByID(clist_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped = self.mapToContactListDict(result)
         return jsonify(User=mapped)
Example #3
0
 def getContactsByUserID(self, user_id):
     dao = ContactListDAO()
     result = dao.getContactsByUserID(user_id)
     if not result:
         return jsonify(Error="NOT FOUND"), 404
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToUserDict(r))
     return jsonify(Users=mapped_result)
Example #4
0
 def deleteContact(self, form):
     if len(form) != 1:
         return jsonify(Error="Malformed post request"), 400
     else:
         contact_id = form['contact_id']
         if contact_id:
             dao = ContactListDAO()
             dao.deleteContact(contact_id)
             return jsonify(DeleteStatus="OK"), 200
Example #5
0
 def getContactListByUserId(self, user_id):
     dao = ContactListDAO()
     result = dao.getContactListByUserID(user_id)
     if result == None:
         return jsonify(Error="NOT FOUND"), 404
     else:
         mapped_result = []
         for r in result:
             mapped_result.append(self.mapToUserDict(r))
         return jsonify(Contacts=mapped_result)
Example #6
0
 def insertContactList(self, form):
     if len(form) != 1:
         return jsonify(Error="Malformed post request"), 400
     else:
         person_id = form['person_id']
         if person_id:
             dao = ContactListDAO()
             clist_id = dao.insertContactList(person_id)
             result = self.mapToContactListDict([clist_id, person_id, None])
             return jsonify(ContactList=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Example #7
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
Example #8
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
Example #9
0
 def getUserContactListID(self, user_id):
     dao = ContactListDAO()
     result = dao.getUserContactListID(user_id)
     if not result:
         return jsonify(Error="NOT FOUND"), 404
     return jsonify(ContactList=self.mapToContactListDict(result))