def deleteResource(self, rid): dao = ResourcesDAO () if not dao.getResourceById (rid): return jsonify (Error="Cannot delete, resource not found."), 404 else: dao.delete (rid) return jsonify (DeleteStatus="OK"), 200
def searchResources(self, args): if len(args) > 2: return jsonify(Error="Malformed search string."), 400 else: rid = args.get("rid") sid = args.get("sid") qty = args.get("qty") dao = ResourcesDAO() resources_list = [] if (len(args) == 1) and rid: resources_list = dao.getResourcesById(rid) elif (len(args) == 1) and sid: resources_list = dao.getResourcesBySupplierId(sid) elif (len(args) == 1) and qty: resources_list = dao.getResourcesByQuantity(qty) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in resources_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def getResourceByPrice(self, rprice_filter): dao = ResourcesDAO () resources_list = dao.getResourceByPrice (rprice_filter) result_list = [] for row in resources_list: result = self.build_allresourcesinfo_dict (row) result_list.append (result) return jsonify (result_list)
def getResourceByDesc(self, descpercent_filter): dao = ResourcesDAO () resources_list = dao.getResourceByDesc (descpercent_filter) result_list = [] for row in resources_list: result = self.build_allresourcesinfo_dict (row) result_list.append (result) return jsonify (result_list)
def getResourcesAvailable(self, rname): dao = ResourcesDAO () resources_list = dao.getResourcesAvailable (rname) result_list = [] for row in resources_list: result = self.build_allresourcesinfo_dict (row) result_list.append (result) return jsonify (result_list)
def getAllResources(self): dao = ResourcesDAO () resources_list = dao.getAllResources () result_list = [] for row in resources_list: result = self.build_allresourcesinfo_dict (row) result_list.append (result) return jsonify (result_list)
def getResourceByCategory(self, rcategory): dao = ResourcesDAO () resources_list = dao.getResourceByCategory (rcategory) result_list = [] for row in resources_list: result = self.build_allresourcesinfo_dict (row) result_list.append (result) return jsonify (result_list)
def getResourceById(self, rid): dao = ResourcesDAO () row = dao.getResourceById (rid) if not row: return jsonify (Error="Resource Not Found"), 404 else: result = self.build_allresourcesinfo_dict (row) return jsonify (result)
def getResourceByRegion(self, rregion): dao = ResourcesDAO () resources_list = dao.getResourceByRegion (rregion) result_list = [] for row in resources_list: result = self.build_allresourcesinfo_dict (row) result_list.append (result) return jsonify (result_list)
def getResourcesById(self, rid): dao = ResourcesDAO() row = dao.getResourcesById(rid) if not row: return jsonify(Error="Resource Not Found"), 404 else: resource = self.build_resource_dict(row) return jsonify(Resource=resource)
def getSupplierByResourcesId(self, rid): dao = ResourcesDAO () if not dao.getSupplierByResourcesId (rid): return jsonify (Error="Supplier Not Found"), 404 resources_list = dao.getSupplierByResourcesId (rid) result_list = [] for row in resources_list: result = self.build_SupplierByResourcesId_dict (row) result_list.append (result) return jsonify (SupplierByResources=result_list)
def getResourcesByQuantity(self, qty): dao = ResourcesDAO() resource_list = dao.getResourcesByQuantity(qty) if not resource_list: return jsonify(Error="No Resource found"), 404 else: result_list = [] for row in resource_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def getSupplierByResourcesId(self, rid): dao = ResourcesDAO() resources_list = dao.getSupplierByResourcesId(rid) suppliers_list = [] if not suppliers_list: return jsonify(Error="Suppliers Not Found"), 404 else: result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers=result_list)
def insertResources(self, form): if len(form) != 2: return jsonify(Error="Malformed POST request"), 400 else: sid = form['sid'] qty = form['qty'] if sid and qty: dao = ResourcesDAO() rid = dao.insert(sid, qty) result = self.build_resource_attributes(rid, sid, qty) return jsonify(Resources=result), 201 else: return jsonify( Error="Unexpected attributes in POST request"), 400
def insertResource(self, form): dao = ResourcesDAO () if len (form) != 7: return jsonify (Error="Malformed post request"), 400 else: # rid = form['rid'] uid = form['uid'] rname = form['rname'] rprice = form['rprice'] descpercent = form['descpercent'] rcategory = form['rcategory'] rqty = form['rqty'] rregion = form['rregion'] if uid and rname and rprice and descpercent and rcategory and rqty and rregion: rid = dao.insert (uid, rname, rprice, descpercent, rcategory, rqty, rregion) result = self.build_allresourcesinfo_dict2 (rid, uid, rname, rprice, descpercent, rcategory, rqty, rregion) return jsonify (Part=result), 201 else: return jsonify (Error="Unexpected attributes in post request"), 400
def updateResource(self, rid, form): dao = ResourcesDAO () if not dao.getResourceById (rid): return jsonify (Error="Resource not found."), 404 else: if len (form) != 8: return jsonify (Error="Malformed update request"), 400 else: rid = form['rid'] uid = form['uid'] rname = form['rname'] rprice = form['rprice'] descpercent = form['descpercent'] rcategory = form['rcategory'] rqty = form['rqty'] rregion = form['rregion'] if rid and uid and rname and rprice and descpercent and rcategory and rqty and rregion: dao.update (rid, uid, rname, rprice, descpercent, rcategory, rqty, rregion) result = self.build_allresourcesinfo_dict2 (rid, uid, rname, rprice, descpercent, rcategory, rqty, rregion) return jsonify (Part=result), 200 else: return jsonify (Error="Unexpected attributes in put request"), 400
def insertWater(self, form): if len(form) != 5: return jsonify(Error = "Malformed POST request"), 400 else: sid = form['sid'] qty = form['qty'] price = form['price'] bsize = form['bsize'] brand = form['brand'] if sid and qty and price and bsize and brand: rid = ResourcesDAO().insert(sid, qty) dao = WaterDAO() dao.insert(rid, price, bsize, brand) result = self.build_water_attributes(rid, price, bsize, brand) return jsonify(Water = result), 201 else: return jsonify(Error="Unexpected attributes in POST request"), 400
def insertIce(self, form): if len(form) != 4: return jsonify(Error="Malformed POST request"), 400 else: sid = form['sid'] qty = form['qty'] price = form['price'] bsize = form['bsize'] if sid and qty and price and bsize: rid = ResourcesDAO().insert(sid, qty) dao = IceDAO() dao.insert(rid, price, bsize) result = self.build_ice_attributes(rid, price, bsize) return jsonify(Ice=result), 201 else: return jsonify( Error="Unexpected attributes in POST request"), 400
def insertTools(self, form): if len(form) != 5: return jsonify(Error="Malformed POST request"), 400 else: sid = form['sid'] qty = form['qty'] name = form['name'] brand = form['brand'] price = form['price'] if sid and qty and name and brand and price: rid = ResourcesDAO().insert(sid, qty) dao = ToolsDAO() dao.insert(rid, name, brand, price) result = self.build_tools_attributes(rid, name, brand, price) return jsonify(Tools=result), 201 else: return jsonify( Error="Unexpected attributes in POST request"), 400
def insertGenerator(self, form): if len(form) != 6: return jsonify(Error="Malformed POST request"), 400 else: sid = form["sid"] quantity = form["quantity"] price = form['price'] brand = form['brand'] fueltype = form['fueltype'] powerrating = form["powerrating"] if sid and quantity and price and brand and fueltype and powerrating: dao = GeneratorDAO() rid = ResourcesDAO().insert(sid, quantity) rid = dao.insert(rid, price, brand, fueltype, powerrating) result = self.build_generator_attributes(rid, price, brand, fueltype, powerrating) return jsonify(Generator=result), 201 else: return jsonify(Error="Unexpected attributes in POST request"), 400
def insertFuel(self, form): if len(form) != 6: return jsonify(Error = "Malformed POST request"), 400 else: sid = form['sid'] qty = form['qty'] ftype = form['ftype'] price = form['price'] csize = form['csize'] brand = form['brand'] if sid and qty and ftype and price and csize and brand: rid = ResourcesDAO().insert(sid, qty) dao = FuelDAO() dao.insert(rid, ftype, price, csize, brand) result = self.build_fuel_attributes(rid, ftype, price, csize, brand) return jsonify(Fuel = result), 201 else: return jsonify(Error="Unexpected attributes in POST request"), 400
def insertEquip(self, form): if len(form) != 6: return jsonify(Error="Malformed POST request"), 400 else: sid = form["sid"] quantity = form["quantity"] price = form['price'] make = form['make'] condition = form['condition'] equipfunction = form["function"] if sid and quantity and price and make and condition and equipfunction: dao = HeavyEquipDAO() rid = ResourcesDAO().insert(sid, quantity) rid = dao.insert(rid, price, make, condition, equipfunction) result = self.build_equip_attributes(rid, price, make, condition, equipfunction) return jsonify(HeavyEquip=result), 201 else: return jsonify(Error="Unexpected attributes in POST request"), 400
def insertBattery(self, form): if len(form) != 5: return jsonify(Error="Malformed POST request"), 400 else: sid = form["sid"] quantity = form["quantity"] price = form['price'] voltage = form['voltage'] btype = form['type'] if sid and quantity and price and voltage and btype: dao = BatteryDAO() rid = ResourcesDAO().insert(sid, quantity) rid = dao.insert(rid, price, voltage, btype) result = self.build_battery_attributes(rid, price, voltage, btype) return jsonify(Battery=result), 201 else: return jsonify( Error="Unexpected attributes in POST request"), 400
def insertClothes(self, form): if len(form) != 7: return jsonify(Error="Malformed POST request"), 400 else: sid = form['sid'] qty = form['qty'] price = form['price'] color = form['color'] size = form['size'] gender = form['gender'] piece = form['piece'] if sid and qty and price and color and size and gender and piece: rid = ResourcesDAO().insert(sid, qty) dao = ClothesDAO() dao.insert(rid, price, color, size, gender, piece) result = self.build_clothes_attributes(rid, price, color, size, gender, piece) return jsonify(Clothes=result), 201 else: return jsonify( Error="Unexpected attributes in POST request"), 400