def getBuyerByID(self, id): dao = BuyerDao() data = dao.getBuyerByID(id) data = self.buildBuyerDictionaries(data) print(len(data)) if len(data) == 0: return jsonify(ERROR="Buyer not found."), 404 return jsonify(Buyer=data)
def insertBuyer(self, form): if form: dao = BuyerDao() name = form.get('AName') lname = form.get('ALastName') email = form.get('AEmail') gender = form.get('AGender') birthdate = form.get('ABDate') phone = form.get('APPhone') sphone = form.get('ASPhone') if name and lname and email and gender and birthdate and phone: buyer = dao.insertBuyer(name, lname, email, gender, birthdate, phone, sphone) account = self._build_account_dict(buyer) return jsonify(Buyer=account), 201 else: return jsonify(Error="Malformed post request"), 400 else: return jsonify(Error="Malformed post request"), 400
def add_credit_card(self, bid, args): if len(args) != 5: return jsonify(ERROR='Malformed URL.'), 404 try: CFullName = args['CFullName'] CNumber = args['CNumber'] CType = args['CType'] CSCode = args['CSCode'] CExpDate = args['CExpDate'] except KeyError: return jsonify(ERROR='Malformed URL.'), 404 dao = BuyerDao() card = dao.insert_card(bid, CFullName, CNumber, CType, CSCode, CExpDate) if card: card = dao.get_card_info(card) card = self.build_card_dictionary(card) return jsonify(Card=card), 201 return jsonify(ERROR='Malformed URL.'), 404
def update_credit_card(self, bid, cnumber, args): dao = BuyerDao() card = None try: CFullName = args['CFullName'] except KeyError as e: CFullName = None try: CSCode = args['CSCode'] except KeyError as e: CSCode = None try: CExpDate = args['CExpDate'] except KeyError as e: CExpDate = None if len(args) == 1: if CFullName: card = dao.update_card_CFullName(bid, cnumber, CFullName) elif CSCode: card = dao.update_card_CSCode(bid, cnumber, CSCode) elif CExpDate: card = dao.update_card_CExpDate(bid, cnumber, CExpDate) elif len(args) == 2: if CFullName and CSCode: card = dao.update_card_CFullName_CSCode( bid, cnumber, CFullName, CSCode) elif CFullName and CExpDate: card = dao.update_card_CFullName_CExpDate( bid, cnumber, CFullName, CExpDate) elif CSCode and CExpDate: card = dao.update_card_CSCode_CExpDate(bid, cnumber, CSCode, CExpDate) elif len(args) == 3: if CFullName and CSCode and CExpDate: card = dao.update_all(bid, cnumber, CFullName, CSCode, CExpDate) if card: card = dao.get_card_info(card) card = self.build_card_dictionary(card) return jsonify(Card=card) return jsonify(ERROR='Malformed URL.'), 404
def getBuyers(self): dao = BuyerDao() data = dao.getBuyers() data = self.buildBuyerDictionaries(data) if len(data) == 0: return jsonify(ERROR="Buyers not found."), 404 return jsonify(Buyer=data)
def findPurchases(self, BID): dao = BuyerDao() data = dao.getBuyerPurchases(BID) data = self.buildBuyerTransactionsDictionaries(data) if len(data) == 0: return jsonify(ERROR="Purchases not found"), 404 return jsonify(BuyerPurchases=data)
def getDonations(self, BID): dao = BuyerDao() data = dao.getBuyerDonations(BID) data = self.buildBuyerTransactionsDictionaries(data) if len(data) == 0: return jsonify(ERROR="Donations not found"), 404 return jsonify(BuyerDonations=data)
def getBuyerRequests(self, id): dao = BuyerDao() data = dao.getBuyerRequests(id) data = self.buildBuyerRequestsDictionaries(data) if len(data) == 0: return jsonify(ERROR="Requests not found"), 404 return jsonify(BuyerRequest=data)