示例#1
0
    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
示例#2
0
    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
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
 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)