def insertDonation(self, form): if len(form) != 5: return jsonify(Error="Malformed post request"), 400 else: date_resolved = form['date_resolved'] supplier_id = form['supplier_id'] victim_id = form['victim_id'] resource_id = form['resource_id'] quantity = int(form['quantity']) if date_resolved and supplier_id and victim_id and resource_id and quantity: isavailable = True print(quantity) if (int(quantity) - 1 <= 0): quantity = 0 print(quantity) isavailable = False else: quantity = int(quantity) - 1 print(quantity) dao = RequestCompletedData() request_completed_id = dao.insertDonation( date_resolved, supplier_id, victim_id, resource_id, str(quantity), isavailable) result = self.build_donation_attributes( request_completed_id, date_resolved, supplier_id, victim_id, resource_id, 0.00, quantity) return jsonify(Donation=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def insertSale(self, form): if len(form) != 6: return jsonify(Error="Malformed post request"), 400 else: date_resolved = form['date_resolved'] supplier_id = form['supplier_id'] victim_id = form['victim_id'] resource_id = form['resource_id'] price = form['price'] quantity = int(form['quantity']) if date_resolved and supplier_id and victim_id and resource_id and price and quantity: dao = RequestCompletedData() request_completed_id = dao.insertSale(date_resolved, supplier_id, victim_id, resource_id, price, int(quantity)) result = self.build_sale_attributes(request_completed_id, date_resolved, supplier_id, victim_id, resource_id, price, quantity) return jsonify(Sale=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def getAllDonation(self): donation_data = RequestCompletedData() donation_list = donation_data.getAllDonation() result_list = [] for row in donation_list: result = self.build_donation_request_completed_dict(row) result_list.append(result) return jsonify(Donation=result_list)
def getAllSales(self): sale_data = RequestCompletedData() sale_list = sale_data.getAllSales() result_list = [] for row in sale_list: result = self.build_sale_request_completed_dict(row) result_list.append(result) return jsonify(Sales=result_list)
def getSaleRequestCompletedByResourceId(self, resource_id): requests_completed_dao = RequestCompletedData() requests_completed_list = requests_completed_dao.getTransactionSaleRequestCompletedByResourceId( resource_id) result_list = [] for row in requests_completed_list: result = self.build_transaction_dict(row) result_list.append(result) return jsonify(Transaction=result_list)
def getRequestCompletedByPrice(self, price): requests_completed_dao = RequestCompletedData() requests_completed_list = requests_completed_dao.getRequestCompletedByPrice( price) result_list = [] for row in requests_completed_list: result = self.build_request_completed_dict(row) result_list.append(result) return jsonify(Requests=result_list)
def getRequestCompletedByCategoryId(self, category_id): requests_completed_dao = RequestCompletedData() requests_completed_list = requests_completed_dao.getRequestCompletedByCategoryId( category_id) result_list = [] for row in requests_completed_list: result = self.build_request_completed_dict(row) result_list.append(result) return jsonify(Requests=result_list)
def getRequestCompletedByVictimId(self, victim_id): requests_completed_dao = RequestCompletedData() requests_completed_list = requests_completed_dao.getRequestCompletedByVictimId( victim_id) result_list = [] for row in requests_completed_list: result = self.build_request_completed_by_victim_id(row) result_list.append(result) return jsonify(Requests=result_list)
def getRequestCompletedByDateResolved(self, date_resolved): requests_completed_dao = RequestCompletedData() requests_completed_list = requests_completed_dao.getRequestCompletedByDateResolved( date_resolved) result_list = [] for row in requests_completed_list: result = self.build_request_completed_dict(row) result_list.append(result) return jsonify(Requests=result_list)
def getAllRequestsCompleted(self): requests_completed_dao = RequestCompletedData() requests_completed_list = requests_completed_dao.getAllRequestsCompleted( ) result_list = [] for row in requests_completed_list: result = self.build_request_completed_dict(row) result_list.append(result) return jsonify(Requests=result_list)