Ejemplo n.º 1
0
    def updateHeavyEquip(self, hequip_id, json):
        hequip_dao = HeavyEquipDAO()
        if not hequip_dao.getHeavyEquipById(hequip_id):
            return jsonify(Error="Heavy Equipment not found."), 404
        else:
            supplier_id = json["supplier_id"]
            category_id = json["category_id"]
            hequip_name = json["hequip_name"]
            hequip_brand = json["hequip_brand"]
            hequip_quantity = json["hequip_quantity"]
            hequip_price = json["hequip_price"]
            hequip_type = json["hequip_type"]
            hequip_model = json["hequip_model"]
            hequip_condition = json["hequip_condition"]

            if supplier_id and category_id and hequip_name and hequip_brand and hequip_quantity and (
                    hequip_price >=
                    0) and hequip_type and hequip_model and hequip_condition:
                resource_id = hequip_dao.update(hequip_id, hequip_type,
                                                hequip_model, hequip_condition)
                resource_dao = ResourceDAO()
                resource_dao.update(resource_id, supplier_id, category_id,
                                    hequip_name, hequip_brand, hequip_quantity,
                                    hequip_price)
                result = self.build_hequip_attributes(
                    hequip_id, resource_id, supplier_id, category_id,
                    hequip_name, hequip_brand, hequip_quantity, hequip_price,
                    hequip_type, hequip_model, hequip_condition)
                return jsonify(HeavyEquipment=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in update request"), 400
Ejemplo n.º 2
0
    def insertHeavyEquip(self, json):
        supplier_id = json["supplier_id"]
        category_id = json["category_id"]
        hequip_name = json["hequip_name"]
        hequip_brand = json["hequip_brand"]
        hequip_quantity = json["hequip_quantity"]
        hequip_price = json["hequip_price"]
        hequip_type = json["hequip_type"]
        hequip_model = json["hequip_model"]
        hequip_condition = json["hequip_condition"]

        if supplier_id and category_id and hequip_name and hequip_brand and hequip_quantity and (
                hequip_price >=
                0) and hequip_type and hequip_model and hequip_condition:
            resource_dao = ResourceDAO()
            resource_id = resource_dao.insert(supplier_id, category_id,
                                              hequip_name, hequip_brand,
                                              hequip_quantity, hequip_price)
            hequip_dao = HeavyEquipDAO()
            hequip_id = hequip_dao.insert(resource_id, hequip_type,
                                          hequip_model, hequip_condition)
            result = self.build_hequip_attributes(
                hequip_id, resource_id, supplier_id, category_id, hequip_name,
                hequip_brand, hequip_quantity, hequip_price, hequip_type,
                hequip_model, hequip_condition)
            return jsonify(HeavyEquipment=result), 201
        else:
            return jsonify(Error="Unexpected attributes in post request"), 400
Ejemplo n.º 3
0
 def getHeavyEquipByResourceId(self, resource_id):
     dao = HeavyEquipDAO()
     row = dao.getHeavyEquipByResourceId(resource_id)
     if not row:
         return jsonify(Error="Heavy Equipment Not Found"), 404
     else:
         hequip = self.build_hequip_dict(row)
         return jsonify(HeavyEquipment=hequip)
Ejemplo n.º 4
0
 def getAllReservedHeavyEquip(self):
     dao = HeavyEquipDAO()
     hequip_list = dao.getAllReservedHeavyEquip()
     result_list = []
     for row in hequip_list:
         result = self.build_hequip_dict(row)
         result_list.append(result)
     return jsonify(HeavyEquipment=result_list)
Ejemplo n.º 5
0
 def deleteHeavyEquip(self, hequip_id):
     hequip_dao = HeavyEquipDAO()
     if not hequip_dao.getHeavyEquipById(hequip_id):
         return jsonify(Error="Heavy Equipment not found."), 404
     else:
         resource_id = hequip_dao.delete(hequip_id)
         resource_dao = ResourceDAO()
         resource_dao.delete(resource_id)
         return jsonify(DeleteStatus="OK"), 200
Ejemplo n.º 6
0
 def getHeavyEquipBySupplierId(self, supplier_id):
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error="Supplier not found."), 404
     else:
         hequip_list = []
         result_list = []
         hequip_dao = HeavyEquipDAO()
         hequip_list = hequip_dao.getHeavyEquipBySupplierId(supplier_id)
         for row in hequip_list:
             result = self.build_hequip_dict(row)
             result_list.append(result)
         return jsonify(HeavyEquipment=result_list)
Ejemplo n.º 7
0
 def getHeavyEquipAddress(self, hequip_id):
     hequip_dao = HeavyEquipDAO()
     try:
         supplier_id = hequip_dao.getHeavyEquipById(hequip_id)[6]
     except Exception:
         return jsonify(Error="Heavy Equipment not found."), 404
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error="Supplier not found."), 404
     else:
         row = hequip_dao.getHeavyEquipAddress(supplier_id)
         if not row:
             return jsonify(Error="Address Not Found"), 404
         else:
             address = self.build_address_dict(row)
             return jsonify(Address=address)
Ejemplo n.º 8
0
 def searchHeavyEquip(self, args):
     hequip_brand = args.get("hequip_brand")
     hequip_type = args.get("hequip_type")
     hequip_condition = args.get("hequip_condition")
     dao = HeavyEquipDAO()
     hequip_list = []
     if (len(args) == 1) and hequip_brand:
         hequip_list = dao.getHeavyEquipByBrand(hequip_brand)
     elif (len(args) == 1) and hequip_type:
         hequip_list = dao.getHeavyEquipByType(hequip_type)
     elif (len(args) == 1) and hequip_condition:
         hequip_list = dao.getHeavyEquipByCondition(hequip_condition)
     else:
         return jsonify(Error="Malformed query string"), 400
     result_list = []
     for row in hequip_list:
         result = self.build_hequip_dict(row)
         result_list.append(result)
     return jsonify(HeavyEquipment=result_list)