def getAllApplicants(self): dao = applicantsDAO() applicants = dao.getAllApplicants() result_list = [] for row in applicants: result = self.build_applicants_dict(row) result_list.append(result) return jsonify(Applicants = result_list)
def getCreditCardsByApl_ID(self, apl_ID): dao = applicantsDAO() row = dao.getCreditCardsByApplicantsID(apl_ID) if not row: return jsonify(Error="Part Not Found"), 404 else: creditcards = self.build_creditcards_dict(row) return jsonify(CreditCards = creditcards)
def getApplicantsById(self, apl_ID): dao = applicantsDAO() row = dao.getApplicantById(apl_ID) if not row: return jsonify(Error = "Part Not Found"), 404 else: applicant = self.build_applicants_dict(row) return jsonify(Applicant = applicant)
def getAllApplicantsInfo(self): dao = applicantsDAO() info = dao.getAllApplicantsInfo() if not info: return jsonify(Error="Part Not Found"), 404 info_list = info result_list = [] for row in info_list: result = self.build_info_dict(row) result_list.append(result) return jsonify(ApplicantsInfo=result_list)
def getApplicantsAddress(self): dao = applicantsDAO() addresses = dao.getAllApplicantsAddress() if not addresses: return jsonify(Error="Part Not Found"), 404 addresses_list = addresses result_list = [] for row in addresses_list: result = self.build_applicantsaddress_dict(row) result_list.append(result) return jsonify(Addresses=result_list)
def insertCreditCard(self, form): if len(form) != 4: return jsonify(Error = "Malform post request"),400 else: card_num = form['card_num'] apl_ID = form['apl_ID'] exp_date = form['exp_date'] balance = form['balance'] if card_num and apl_ID and exp_date and balance: dao = applicantsDAO() dao.insertCreditCard(card_num,apl_ID,exp_date,balance) result = self.build_creditcards_attributes(card_num,apl_ID,exp_date, balance) return jsonify(Credit_Cards = result),201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def updateCreditCards(self,card_num,form): dao = applicantsDAO() if not dao.getAccountByCardNum(card_num): return jsonify(Error = "Account not found"), 404 else: if len(form)!=4: return jsonify(Error = "Malform update request"),400 else: card_num=form['card_num'] apl_ID=form['apl_ID'] exp_date = form['exp_date'] balance = form['balance'] if balance and exp_date and apl_ID and card_num: dao.updateCreditCard(exp_date,balance,card_num) result = self.build_creditcards_attributes(card_num,apl_ID,exp_date,balance) return jsonify (Credit_Card = result),200 else: return jsonify(Error = "Unexpected attributes in updates request"), 400
def insertApplicants(self, form): if len(form) != 9: return jsonify(Error = "Malform post request"),400 else: first_name = form['first_name'] last_name = form['last_name'] street = form['street'] urb_conde = form['urb_conde'] num = form['num'] city = form['city'] state = form ['state'] zip = form['zip'] gps_local = form['gps_local'] if first_name and last_name and street and urb_conde and num and city and state and zip and gps_local: dao = applicantsDAO() apl_id = dao.insert(first_name,last_name) dao.insertAddress(apl_id,street,urb_conde,num,city,state,zip,gps_local) result = self.build_applicants_attributes(apl_id,first_name,last_name, street,urb_conde,num,city,state,zip,gps_local) return jsonify(Applicant = result),201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def searchApplicants(self, args): name = args.get("first_name") lastname = args.get("last_name") location = args.get("location") region = args.get("region") dao = applicantsDAO() applicants_list = [] if (len(args) == 2) and name and location: applicants_list = dao.getApplicantsByNameAndLocation(name, location) elif (len(args) == 2) and name and region: applicants_list = dao.getApplicantsByNameAndRegion(name, region) elif (len(args) == 1) and location: applicants_list = dao.getApplicantsByLocation(location) elif (len(args) == 1) and region: applicants_list = dao.getApplicantsByRegion(region) elif (len(args) == 2) and name and lastname: applicants_list = dao.getApplicantsByNameAndLastname(name, lastname) else: return jsonify(Error = "Malformed query string"), 400 result_list = [] for row in applicants_list: result = self.build_applicants_dict(row) result_list.append(result) return jsonify(Applicants=result_list)