Ejemplo n.º 1
0
 def getAllReservedTools(self):
     dao = ToolDAO()
     tool_list = dao.getAllReservedTools()
     result_list = []
     for row in tool_list:
         result = self.build_tool_dict(row)
         result_list.append(result)
     return jsonify(Tools = result_list)
Ejemplo n.º 2
0
 def getToolByResourceId(self, resource_id):
     dao = ToolDAO()
     row = dao.getToolByResourceId(resource_id)
     if not row:
         return jsonify(Error = "Tool Not Found"), 404
     else:
         tool = self.build_tool_dict(row)
         return jsonify(Tool = tool)
Ejemplo n.º 3
0
 def deleteTool(self, tool_id):
     tool_dao = ToolDAO()
     if not tool_dao.getToolById(tool_id):
         return jsonify(Error = "Tool not found."), 404
     else:
         resource_id = tool_dao.delete(tool_id)
         resource_dao = ResourceDAO()
         resource_dao.delete(resource_id)
         return jsonify(DeleteStatus = "OK"), 200
Ejemplo n.º 4
0
 def getToolsBySupplierId(self, supplier_id):
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error = "Supplier not found."), 404
     else:
         tool_list = []
         result_list = []
         tool_dao = ToolDAO()
         tool_list = tool_dao.getToolsBySupplierId(supplier_id)
         for row in tool_list:
             result = self.build_tool_dict(row)
             result_list.append(result)
         return jsonify(Tools = result_list)
Ejemplo n.º 5
0
 def getToolAddress(self, tool_id):
     tool_dao = ToolDAO()
     try:
         supplier_id = tool_dao.getToolById(tool_id)[5]
     except Exception:
         return jsonify(Error = "Tool not found."), 404
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error = "User not found."), 404
     else:
         row = tool_dao.getToolAddress(supplier_id)
         if not row:
             return jsonify(Error = "Address not found."), 404
         else:
             tool_address = self.build_address_dict(row)
             return jsonify(Address = tool_address)
Ejemplo n.º 6
0
    def searchTools(self, args):
        tool_brand = args.get("tool_brand")
        tool_material = args.get("tool_material")
        tool_condition = args.get("tool_condition")
        tool_pwtype = args.get("tool_pwtype")

        dao = ToolDAO()
        tool_list = []
        if (len(args) == 1) and tool_brand:
            tool_list = dao.getToolsByBrand(tool_brand)
        elif (len(args) == 1) and tool_material:
            tool_list = dao.getToolsByMaterial(tool_material)
        elif (len(args) == 1) and tool_condition:
            tool_list = dao.getToolsByCondition(tool_condition)
        elif (len(args) == 1) and tool_pwtype:
            tool_list = dao.getToolsByPowerType(tool_pwtype)
        elif (len(args) == 2) and tool_material and tool_pwtype:
            tool_list = dao.getToolsByMaterialAndPowerType(tool_material, tool_pwtype)
        else:
            return jsonify(Error = "Malformed query string"), 400
        result_list = []
        for row in tool_list:
            result = self.build_tool_dict(row)
            result_list.append(result)
        return jsonify(Tools = result_list)
Ejemplo n.º 7
0
    def insertTool(self, json):
        supplier_id = json["supplier_id"]
        category_id = json['category_id']
        tool_name = json["tool_name"]
        tool_brand = json["tool_brand"]
        tool_quantity = json["tool_quantity"]
        tool_price = json["tool_price"]
        tool_material = json["tool_material"]
        tool_condition = json["tool_condition"]
        tool_pwtype = json["tool_pwtype"]

        if supplier_id and category_id and tool_name and tool_brand and (tool_quantity>=0) and (tool_price>=0) and tool_material and tool_condition and tool_pwtype:
            resource_dao = ResourceDAO()
            resource_id = resource_dao.insert(supplier_id, category_id, tool_name, tool_brand, tool_quantity, tool_price)
            tool_dao = ToolDAO()
            tool_id = tool_dao.insert(resource_id, tool_material, tool_condition, tool_pwtype)
            result = self.build_tool_attributes(tool_id, resource_id, supplier_id, category_id, tool_name, tool_brand, tool_quantity, tool_price, tool_material, tool_condition, tool_pwtype)
            return jsonify(Tool = result), 201
        else:
            return jsonify(Error = "Unexpected attributes in post request"), 400
Ejemplo n.º 8
0
    def updateTool(self, tool_id, json):
        tool_dao = ToolDAO()
        if not tool_dao.getToolById(tool_id):
            return jsonify(Error = "Tool not found."), 404
        else:
            supplier_id = json["supplier_id"]
            category_id = json['category_id']
            tool_name = json["tool_name"]
            tool_brand = json["tool_brand"]
            tool_quantity = json["tool_quantity"]
            tool_price = json["tool_price"]
            tool_material = json["tool_material"]
            tool_condition = json["tool_condition"]
            tool_pwtype = json["tool_pwtype"]

            if supplier_id and category_id and tool_name and tool_brand and (tool_quantity>=0) and (tool_price>=0) and tool_material and tool_condition and tool_pwtype:
                resource_id = tool_dao.update(tool_id, tool_material, tool_condition, tool_pwtype)
                resource_dao = ResourceDAO()
                resource_dao.update(resource_id, supplier_id, category_id, tool_name, tool_brand, tool_quantity, tool_price)
                result = self.build_tool_attributes(tool_id, resource_id, supplier_id, category_id, tool_name, tool_brand, tool_quantity, tool_price, tool_material, tool_condition, tool_pwtype)
                return jsonify(Tool = result), 200
            else:
                return jsonify(Error = "Unexpected attributes in update request"), 400