def addUserToContactList(self, uID, json): dao = UserDAO() if json.get('firstname')==None or json.get('lastname')==None\ or not(json.get('phone')==None or json.get('email')==None): return jsonify(Error="Malformed post request"), 400 else: firstname = json['firstname'] lastname = json['lastname'] if json.get('phone') != None: phone = json['phone'] email = None elif json.get('email') != None: email = json['email'] phone = None else: phone = email = None if firstname and lastname and phone: uID = dao.addContact(uID, firstname, lastname, phone, None) result = "User was added to contactlist" return jsonify(result), 201 elif firstname and lastname and email: uID = dao.addContact(uID, firstname, lastname, None, email) result = "User was added to contactlist" return jsonify(result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def deleteFriendById(self, fuid): dao = UserDAO() if not dao.getFriendByUserId(fuid): return jsonify(Error="User not found."), 404 else: dao.deleteFriendById(fuid) return jsonify(DeleteStatus="OK"), 200
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)
def getUserByUserName(self, username): dao = UserDAO() result = dao.getUserByUserName(username) if not result: return jsonify(Error="Not Found"), 404 else: return jsonify(User=self.mapToDict(result))
def insertAddress(self, json): user_id = json["user_id"] addressline = json["addressline"] city = json["city"] state_province = json["state_province"] country = json["country"] zipcode = json["zipcode"] user_dao = UserDAO() if not user_dao.getUserById(user_id): return jsonify(Error="User not found."), 404 else: if user_id and addressline and city and state_province and country and zipcode: address_dao = AddressDAO() address_id = address_dao.insert(user_id, addressline, city, state_province, country, zipcode) result = self.build_address_attributes(address_id, user_id, addressline, city, state_province, country, zipcode) return jsonify(Address=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def getGroupChatsByUserId(self, userid): dao = UserDAO() result = dao.getGroupChatsByUserId(userid) result_map = [] for r in result: result_map.append(self.build_groupChat_dict(r)) return jsonify(GroupChats=result_map)
def login(self, username, password): dao = UserDAO() result = dao.verify(username, password) if not result: return 0 else: return result[0]
def getUserGroups(self, pid): dao = UserDAO() group_list = dao.getUserGroups(pid) result_list = [] for row in group_list: result_list.append(self.build_user_groups_dict(row)) return jsonify(My_Groups=result_list)
def searchUsers(self, args): dao = UserDAO() result = dao.searchByUsername(str(args)) if not result: return jsonify(Error="USER NOT FOUND"), 404 else: return jsonify(User=result)
def deleteUser(self, pid): dao = UserDAO() if not dao.getUserById(pid): return jsonify(Error="User not found."), 404 else: dao.delete(pid) return jsonify(DeleteStatus="OK"), 200
def getAllUsers(self): dao = UserDAO() result = dao.getAllUsers() mappedResult = [] for r in result: mappedResult.append(self.mapToDictionary(r)) return jsonify(Users=mappedResult)
def getAllUsers(self): dao = UserDAO() user_list = dao.getAllUsers() result_list = [] for row in user_list: result_list.append(self.build_user_dict(row)) return jsonify(Users=result_list)
def getOwnerOfGroupChatById(self, groupchatid): dao = UserDAO() row = dao.getOwnerOfGroupChatById(groupchatid) result_map = [] for r in row: result_map.append(self.build_user_dict(r)) return jsonify(Owner=result_map)
def getUserContacts(self, pid): dao = UserDAO() contact_list = dao.getUserContacts(pid) result_list = [] for row in contact_list: result_list.append(self.build_user_dict(row)) return jsonify(My_contacts=result_list)
def getUserById(self, uID): dao = UserDAO() result = dao.getUserByID(uID) if not result: return jsonify(Error="Not found"), 404 mapped_result = mapUserToDict(result) return jsonify(mapped_result)
def updateCustomer(self, customer_id, json): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer not found."), 404 else: customer_firstname = json["customer_firstname"] customer_lastname = json["customer_lastname"] customer_date_birth = json["customer_date_birth"] customer_email = json["customer_email"] customer_phone = json["customer_phone"] customer_phone_id = json["customer_phone_id"] if customer_firstname and customer_lastname and customer_date_birth and customer_email and customer_phone_id and customer_phone: user_id = customer_dao.update(customer_id) user_dao = UserDAO() user_dao.update(user_id, customer_firstname, customer_lastname, customer_date_birth, customer_email) dao_phone = UserPhoneDAO() dao_phone.update(user_id, customer_phone) result = self.build_customer_attributes( customer_id, user_id, customer_firstname, customer_lastname, customer_date_birth, customer_email, customer_phone_id, customer_phone) return jsonify(Customer=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def updateAdmin(self, admin_id, json): dao_admin = AdminDAO() if not dao_admin.getAdminById(admin_id): return jsonify(Error="Admin not found."), 404 else: admin_firstname = json['admin_firstname'] admin_lastname = json['admin_lastname'] admin_date_birth = json['admin_date_birth'] admin_email = json['admin_email'] admin_phone = json['admin_phone'] admin_phone_id = json["admin_phone_id"] if admin_firstname and admin_lastname and admin_date_birth and admin_email and admin_phone and admin_phone_id: user_id = dao_admin.update(admin_id) dao_user = UserDAO() dao_user.update(user_id, admin_firstname, admin_lastname, admin_date_birth, admin_email) dao_phone = UserPhoneDAO() dao_phone.update(user_id, admin_phone) result = self.build_admin_attributes( user_id, admin_id, admin_firstname, admin_lastname, admin_date_birth, admin_email, admin_phone_id, admin_phone) return jsonify(Admin=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def getUserByID(self, uid): dao = UserDAO() result = dao.getUserByID(uid) if not result: return jsonify(Error="Not Found"), 404 else: return jsonify(User=self.mapToDict(result))
def deleteAccount(self, uid): dao = UserDAO() if not dao.getUserByUserId(uid): return jsonify(Error="User not found."), 404 else: dao.deleteAccount(uid) return jsonify(DeleteStatus="OK"), 200
def updateUser(self, uid, form): dao = UserDAO() if not dao.getUserByUserId(uid): return jsonify(Error="User not found."), 404 else: if len(form) != 8: return jsonify(Error="Malformed update request"), 400 else: username = form['username'] password = form['password'] birth_date = form['birth_date'] first_name = form['first_name'] last_name = form['last_name'] email = form['email'] phone = form['phone'] profile_picture = form['profile_picture'] date = dt.datetime.now().strftime("%m/%d/%Y") if profile_picture and phone and email and last_name and first_name and birth_date and username \ and password: dao.updateUser(uid, username, password, birth_date, first_name, last_name, email, phone, profile_picture) result = self.build_user_update_attributes( uid, username, date, profile_picture) return jsonify(User=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def registerUser(self, name, email, username, password, phone): dao = UserDAO() dao.register(name, email, username, password, phone) return jsonify(Register="User with name: '" + name + "',username: '******', email: '" + email + "', password: '******' and phone: '" + phone + "' has been registered")
def getUserById(self, pid): dao = UserDAO() row = dao.getUserById(pid) if not row: return jsonify(Error="User Not Found"), 404 else: user = self.build_user_dict(row) return jsonify(User=user)
def getUserInformationByUsername(self, username): dao = UserDAO() result = dao.getUserInformationByUsername(username) if result is None: return jsonify(Error="User doesn't exist!") else: result_map = self.build_userinfo_dict(result) return jsonify(Users=result_map)
def getUserContactsByUserId(self, userid): dao = UserDAO() user_list = dao.getUserContactsByUserId(userid) result_map = [] for row in user_list: result = self.build_user_dict(row) result_map.append(result) return jsonify(Users=result_map)
def getUserByID(self, id): dao = UserDAO() result = dao.getUserById(id) if result == None: return jsonify(Error="USER NOT FOUND") else: mapped = self.mapToDict(result) return jsonify(User=mapped)
def getUsersInGroupChatByUserIdAndGroupChatId(self, userid, groupchatid): dao = UserDAO() result = dao.getUsersInGroupChatByUserIdAndGroupChatId( userid, groupchatid) result_map = [] for r in result: result_map.append(self.build_user_dict(r)) return jsonify(Users=result_map), 201
def deleteAdmin(self, aid): dao = UserDAO() result = dao.deleteAdmin(aid) if result: return jsonify(Admin=result), 201 else: return jsonify(Error="Supplier not found"), 404
def getUserByUserId(self, userid): dao = UserDAO() result = dao.getUserByUserId(userid) if result is None: return jsonify(Error="User doesn't exist!") else: result_map = self.build_user_dict(result) return jsonify(Users=result_map)
def getMostActiveUser(self): dao = UserDAO() result = dao.getMostActiveUser() if not result: return jsonify(Error="Not found"), 404 mapped_result = [] for r in result: mapped_result.append(mapMostActiveUserToDict(r)) return jsonify(mapped_result)
def getToWhatGroupUserIsMember(self, uID): dao = UserDAO() result = dao.getToWhatGroupUserIsMember(uID) if not result: return jsonify(Error="Not found"), 404 mapped_result = [] for r in result: mapped_result.append(mapGroupToDict(r)) return jsonify(mapped_result)