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
def updateBattery(self, battery_id, json): battery_dao = BatteryDAO() if not battery_dao.getBatteryById(battery_id): return jsonify(Error = "Battery not found."), 404 else: supplier_id = json['supplier_id'] category_id = json['category_id'] battery_name = json['battery_name'] battery_brand = json['battery_brand'] battery_quantity = json['battery_quantity'] battery_price = json['battery_price'] power_capacity = json['power_capacity'] power_condition = json['power_condition'] battery_type = json['battery_type'] if supplier_id and category_id and battery_name and battery_brand and battery_quantity and (battery_price>=0) and power_capacity and power_condition and battery_type: resource_id = battery_dao.update(battery_id, power_capacity, power_condition, battery_type) res_dao = ResourceDAO() res_dao.update(resource_id, supplier_id, category_id, battery_name, battery_brand, battery_quantity, battery_price) result = self.build_battery_attributes(supplier_id, resource_id, battery_id, category_id, battery_name, battery_brand, battery_quantity, battery_price, power_capacity, power_condition, battery_type) return jsonify(Battery = result), 200 else: return jsonify(Error = "Unexpected attributes in update request"), 400
def updateMedDevice(self, med_device_id, json): med_device_dao = MedDeviceDAO() if not med_device_dao.getMedDeviceById(med_device_id): return jsonify(Error = "Medical Device not found."), 404 else: supplier_id = json["supplier_id"] category_id = json["category_id"] med_device_name = json["med_device_name"] med_device_brand = json["med_device_brand"] med_device_quantity = json["med_device_quantity"] med_device_price = json["med_device_price"] med_device_type = json["med_device_type"] med_device_model = json["med_device_model"] med_device_condition = json["med_device_condition"] med_device_power_type = json["med_device_power_type"] if supplier_id and category_id and med_device_name and med_device_brand and med_device_quantity and (med_device_price>=0) and med_device_type and med_device_model and med_device_condition and med_device_power_type: resource_id = med_device_dao.update(med_device_id, med_device_type, med_device_model, med_device_condition, med_device_power_type) resource_dao = ResourceDAO() resource_dao.update(resource_id, supplier_id, category_id, med_device_name, med_device_brand, med_device_quantity, med_device_price) result = self.build_med_device_attributes(med_device_id, resource_id, supplier_id, category_id, med_device_name, med_device_brand, med_device_quantity, med_device_price, med_device_type, med_device_model, med_device_condition, med_device_power_type) return jsonify(Medical_Device = result), 200 else: return jsonify(Error = "Unexpected attributes in update request"), 400
def insertAvailableResource(self, form): if form and len(form) == 5: rqty = form['rqty'] rprice = form['rprice'] rcondition = form['rcondition'] rid = form['rid'] sid = form['sid'] #isHidden = form['isHidden'] if rqty and rprice and rcondition and rid and sid: dao = ResourceDAO() iid = dao.insertAvailableResource(rqty, rprice, rcondition, rid, sid) #change to a method that returns the resource name, price, supplier, condition and quantity. result = {} result['RQty'] = rqty result['RPrice'] = rprice result['RCondition'] = rcondition result['RID'] = rid result['SID'] = sid return jsonify(Resource=result), 201 else: return jsonify(Error="Malformed post request"), 400 else: return jsonify(Error="Malformed post request"), 400
def updateCloth(self, cloth_id, json): cloth_dao = ClothDAO() if not cloth_dao.getClothById(cloth_id): return jsonify(Error="Cloth not found."), 404 else: supplier_id = json["supplier_id"] category_id = json["category_id"] cloth_name = json["cloth_name"] cloth_brand = json["cloth_brand"] cloth_quantity = json["cloth_quantity"] cloth_price = json["cloth_price"] cloth_size = json["cloth_size"] cloth_material = json["cloth_material"] cloth_condition = json["cloth_condition"] cloth_gender = json["cloth_gender"] cloth_type = json["cloth_type"] if supplier_id and category_id and cloth_name and cloth_brand and cloth_quantity and ( cloth_price >= 0 ) and cloth_size and cloth_material and cloth_condition and cloth_gender and cloth_type: resource_id = cloth_dao.update(cloth_id, cloth_size, cloth_material, cloth_condition, cloth_gender, cloth_type) resource_dao = ResourceDAO() resource_dao.update(resource_id, supplier_id, category_id, cloth_name, cloth_brand, cloth_quantity, cloth_price) result = self.build_cloth_attributes( cloth_id, resource_id, supplier_id, category_id, cloth_name, cloth_brand, cloth_quantity, cloth_price, cloth_size, cloth_material, cloth_condition, cloth_gender, cloth_type) return jsonify(Cloth=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def updateResource(self, r_id, form): dao = ResourceDAO() if not dao.getResourceById(r_id): return jsonify(Error = "Resource not found."), 404 else: if len(form) != 3: return jsonify(Error="Malformed update Resource"), 400 else: r_name = form['r_name'] r_category = form['r_category'] r_type = form['r_type'] if r_name and r_category and r_type: dao = ResourceDAO() dao.update(r_id, r_name, r_category, r_type) result = self.build_resource_attributes(r_id, r_name, r_category, r_type) return jsonify(Resource=result), 201 else: return jsonify(Error="Unexpected attributes in update Resource"), 400
def searchKeywordsByResourceId(self, rsid, args): if not ResourceDAO().getResourceById(rsid): return jsonify(Error="Resource Not Found"), 404 else: keyword = args.get('keyword') dao = KeywordDAO() keyword_list = [] if (len(args) == 1) and keyword: keyword_list = dao.getKeywordsByResourceIdByKeyword( rsid, keyword) else: return jsonify(Error="Malformed Query String"), 400 result_list = [] for row in keyword_list: result = self.build_keyword_dict(row) result_list.append(result) if not result_list: return jsonify(Error="Keyword Not Found"), 404 else: return jsonify(Keywords=result_list)
def getStatistic(self): dao= ResourceDAO() result_list = [] result = [] result.append(['Resources', 'Needed']) resources_list = dao.getDNStats() for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getDAStats() for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getDMStats() for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getWNStats() for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getWAStats() for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getWMStats() for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getRNStats("Ponce") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getRAStats("Ponce") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getRMStats("Ponce") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getRNStats("Arecibo") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getRAStats("Arecibo") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getRMStats("Arecibo") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getRNStats("Mayaguez") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getRAStats("Mayaguez") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getRMStats("Mayaguez") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getRNStats("Caguas") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getRAStats("Caguas") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getRMStats("Caguas") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getRNStats("Bayamon") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getRAStats("Bayamon") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getRMStats("Bayamon") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getRNStats("San Juan") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getRAStats("San Juan") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getRMStats("San Juan") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Needed']) resources_list = dao.getRNStats("Humacao") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Available']) resources_list = dao.getRAStats("Humacao") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) result = [] result.append(['Resources', 'Matching']) resources_list = dao.getRMStats("Humacao") for row in resources_list: temp = self.build_stat_dict(row) result.append(temp) result_list.append(result) return result_list
def updateInventory(self, form): if form: rid = form.get('rid') sid = form.get('sid') rqty = form.get('rqty') rprice = form.get('rprice') rcondition = form.get('rcondition') isHidden = form.get('isHidden') result = {} dao = ResourceDAO() # if (len(form) == 3) and rid and sid and isHidden: # dao.hideInventory(rid, sid, isHidden) # result['RID'] = rid # result['SID'] = sid # result['isHidden'] = isHidden inventory_exist = dao.getInventoryBySIDAndRID(sid, rid) if not inventory_exist: return jsonify(Error='Inventory Not Found'), 404 if (len(form) == 5) and rid and sid and rprice and rcondition and rqty: dao.updateInventoryQtyAndPriceAndCondition( rqty, rprice, rcondition, rid, sid) result['RID'] = rid result['SID'] = sid result['RQty'] = rqty result['RPrice'] = rprice result['RCondition'] = rcondition elif (len(form) == 4) and rid and sid and rprice and rcondition: dao.updateInventoryPriceAndCondition(rprice, rcondition, rid, sid) result['RID'] = rid result['SID'] = sid result['RPrice'] = rprice result['RCondition'] = rcondition elif (len(form) == 4) and rid and sid and rprice and rqty: dao.updateInventoryQtyAndPrice(rqty, rprice, rid, sid) result['RID'] = rid result['SID'] = sid result['RQty'] = rqty result['RPrice'] = rprice elif (len(form) == 4) and rid and sid and rcondition and rqty: dao.updateInventoryQtyAndCondition(rqty, rcondition, rid, sid) result['RID'] = rid result['SID'] = sid result['RQty'] = rqty result['RCondition'] = rcondition elif (len(form) == 3) and rid and sid and rprice: dao.updateInventoryPrice(rprice, rid, sid) result['RID'] = rid result['SID'] = sid result['RPrice'] = rprice elif (len(form) == 3) and rid and sid and rcondition: print('ENtra') dao.updateInventoryCondition(rcondition, rid, sid) result['RID'] = rid result['SID'] = sid result['RCondition'] = rcondition elif (len(form) == 3) and rid and sid and rqty: dao.updateInventoryQty(rqty, rid, sid) result['RID'] = rid result['SID'] = sid result['RQty'] = rqty else: return jsonify(Error="Malformed query string"), 400 return jsonify(Resource=result), 201 #Returns tuple after update else: return jsonify(Error="Malformed post request"), 400
def searchResources(self, args): rname = args.get('rname') r_changed_date = args.get('r_changed_date') rqty = args.get('rqty') rprice = args.get('rprice') r_supply_date = args.get('r_supply_date') dao = ResourceDAO() resource_list = [] if (len(args) == 5) and rname and r_changed_date and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByNameChangedDateQtyPriceSupplyDate(Name, ChangedDate, Qty, Price, SupplyDate) elif (len(args) == 4) and rname and r_changed_date and rqty and rprice: resource_list = dao.getResourcesByNameChangedDateQtyPrice(Name, ChangedDate, Qty, Price) elif (len(args) == 4) and rname and r_changed_date and rqty and r_supply_date: resource_list = dao.getResourcesByNameChangedDateQtySupplyDate(Name, ChangedDate, Qty, SupplyDate) elif (len(args) == 4) and rname and r_changed_date and rprice and r_supply_date: resource_list = dao.getResourcesByNameChangedDatePriceSupplyDate(Name, ChangedDate, Price, SupplyDate) elif (len(args) == 4) and rname and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByNameQtyPriceSupplyDate(Name, Qty, Price, SupplyDate) elif (len(args) == 4) and r_changed_date and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByChangedDateQtyPriceSupplyDate(ChangedDate, Qty, Price, SupplyDate) elif (len(args) == 3) and rname and r_changed_date and rqty: resource_list = dao.getResourcesByNameChangedDateQty(Name, ChangedDate, Qty) elif (len(args) == 3) and rname and r_changed_date and rprice: resource_list = dao.getResourcesByNameChangedDatePrice(Name, ChangedDate, Price) elif (len(args) == 3) and rname and r_changed_date and r_supply_date: resource_list = dao.getResourcesByNameChangedDateSupplyDate(Name, ChangedDate, SupplyDate) elif (len(args) == 3) and rname and rqty and rprice: resource_list = dao.getResourcesByNameQtyPrice(Name, Qty, Price) elif (len(args) == 3) and rname and rqty and r_supply_date: resource_list = dao.getResourcesByNameQtySupplyDate(Name, Qty, SupplyDate) elif (len(args) == 3) and rname and rprice and r_supply_date: resource_list = dao.getResourcesByNamePriceSupplyDate(Name, Price, SupplyDate) elif (len(args) == 3) and r_changed_date and rqty and rprice: resource_list = dao.getResourcesByChangedDateQtyPrice(ChangedDate, Qty, Price) elif (len(args) == 3) and r_changed_date and rqty and r_supply_date: resource_list = dao.getResourcesByChangedDateQtySupplyDate(ChangedDate, Qty, SupplyDate) elif (len(args) == 3) and r_changed_date and rprice and r_supply_date: resource_list = dao.getResourcesByChangedDatePriceSupplyDate(ChangedDate, Price, SupplyDate) elif (len(args) == 3) and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByQtyPriceSupplyDate(Qty, Price, SupplyDate) elif (len(args) == 2) and rname and r_changed_date: resource_list = dao.getResourcesByNameChangedDate(Name, ChangedDate) elif (len(args) == 2) and rname and rqty: resource_list = dao.getResourcesByNameQty(Name, Qty) elif (len(args) == 2) and rname and rprice: resource_list = dao.getResourcesByNamePrice(Name, Price) elif (len(args) == 2) and rname and r_supply_date: resource_list = dao.getResourcesByNameSupplyDate(Name, SupplyDate) elif (len(args) == 2) and r_changed_date and rqty: resource_list = dao.getResourcesByChangedDateQty(ChangedDate, Qty) elif (len(args) == 2) and r_changed_date and rprice: resource_list = dao.getResourcesByChangedDatePrice(ChangedDate, Price) elif (len(args) == 2) and r_changed_date and r_supply_date: resource_list = dao.getResourcesByChangedDateSupplyDate(ChangedDate, SupplyDate) elif (len(args) == 2) and rqty and rprice: resource_list = dao.getResourcesByQtyPrice(Qty, Price) elif (len(args) == 2) and rqty and r_supply_date: resource_list = dao.getResourcesByQtySupplyDate(Qty, SupplyDate) elif (len(args) == 2) and rprice and r_supply_date: resource_list = dao.getResourcesByPriceSupplyDate(Price, SupplyDate) elif (len(args) == 1) and rname: resource_list = dao.getResourcesByName(Name) elif (len(args) == 1) and r_changed_date: resource_list = dao.getResourcesByChangedDate(ChangedDate) elif (len(args) == 1) and rqty: resource_list = dao.getResourcesByQty(Qty) elif (len(args) == 1) and rprice: resource_list = dao.getResourcesByPrice(Price) elif (len(args) == 1) and r_supply_date: resource_list = dao.getResourcesBySupplyDate(SupplyDate) else: return jsonify(Error = "Malformed Query String"), 400 result_list = [] for row in resource_list: result = self.build_resource_dict(row) result_list.append(result) if not result_list: return jsonify(Error = "Resource Not Found"), 404 else: return jsonify(Resources = result_list)
class ResourceHandler: def build_resource_dict(self, row): result = {} result['rsid'] = row[0] result['rname'] = row[1] result['rdescription'] = row[2] result['r_changed_date'] = row[3] result['rqty'] = row[4] result['rprice'] = row[5] result['r_supply_date'] = row[6] return result def build_resource_attributes(self, rsid, rname, rdescription, r_changed_date, rqty, rprice, r_supply_date): result = {} result['rsid'] = rsid result['rname'] = rname result['rdescription'] = rdescription result['r_changed_date'] = r_changed_date result['rqty'] = rqty result['rprice'] = rprice result['r_supply_date'] = r_supply_date return result def getAllResources(self): dao = ResourceDAO() resource_list = dao.getAllResources() result_list = [] for row in resource_list: result = self.build_resource_dict(row) result_list.append(result) if not result_list: return jsonify(Error = "Resources Not Found"), 404 else: return jsonify(Resources = result_list) def searchResources(self, args): rname = args.get('rname') r_changed_date = args.get('r_changed_date') rqty = args.get('rqty') rprice = args.get('rprice') r_supply_date = args.get('r_supply_date') dao = ResourceDAO() resource_list = [] if (len(args) == 5) and rname and r_changed_date and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByNameChangedDateQtyPriceSupplyDate(Name, ChangedDate, Qty, Price, SupplyDate) elif (len(args) == 4) and rname and r_changed_date and rqty and rprice: resource_list = dao.getResourcesByNameChangedDateQtyPrice(Name, ChangedDate, Qty, Price) elif (len(args) == 4) and rname and r_changed_date and rqty and r_supply_date: resource_list = dao.getResourcesByNameChangedDateQtySupplyDate(Name, ChangedDate, Qty, SupplyDate) elif (len(args) == 4) and rname and r_changed_date and rprice and r_supply_date: resource_list = dao.getResourcesByNameChangedDatePriceSupplyDate(Name, ChangedDate, Price, SupplyDate) elif (len(args) == 4) and rname and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByNameQtyPriceSupplyDate(Name, Qty, Price, SupplyDate) elif (len(args) == 4) and r_changed_date and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByChangedDateQtyPriceSupplyDate(ChangedDate, Qty, Price, SupplyDate) elif (len(args) == 3) and rname and r_changed_date and rqty: resource_list = dao.getResourcesByNameChangedDateQty(Name, ChangedDate, Qty) elif (len(args) == 3) and rname and r_changed_date and rprice: resource_list = dao.getResourcesByNameChangedDatePrice(Name, ChangedDate, Price) elif (len(args) == 3) and rname and r_changed_date and r_supply_date: resource_list = dao.getResourcesByNameChangedDateSupplyDate(Name, ChangedDate, SupplyDate) elif (len(args) == 3) and rname and rqty and rprice: resource_list = dao.getResourcesByNameQtyPrice(Name, Qty, Price) elif (len(args) == 3) and rname and rqty and r_supply_date: resource_list = dao.getResourcesByNameQtySupplyDate(Name, Qty, SupplyDate) elif (len(args) == 3) and rname and rprice and r_supply_date: resource_list = dao.getResourcesByNamePriceSupplyDate(Name, Price, SupplyDate) elif (len(args) == 3) and r_changed_date and rqty and rprice: resource_list = dao.getResourcesByChangedDateQtyPrice(ChangedDate, Qty, Price) elif (len(args) == 3) and r_changed_date and rqty and r_supply_date: resource_list = dao.getResourcesByChangedDateQtySupplyDate(ChangedDate, Qty, SupplyDate) elif (len(args) == 3) and r_changed_date and rprice and r_supply_date: resource_list = dao.getResourcesByChangedDatePriceSupplyDate(ChangedDate, Price, SupplyDate) elif (len(args) == 3) and rqty and rprice and r_supply_date: resource_list = dao.getResourcesByQtyPriceSupplyDate(Qty, Price, SupplyDate) elif (len(args) == 2) and rname and r_changed_date: resource_list = dao.getResourcesByNameChangedDate(Name, ChangedDate) elif (len(args) == 2) and rname and rqty: resource_list = dao.getResourcesByNameQty(Name, Qty) elif (len(args) == 2) and rname and rprice: resource_list = dao.getResourcesByNamePrice(Name, Price) elif (len(args) == 2) and rname and r_supply_date: resource_list = dao.getResourcesByNameSupplyDate(Name, SupplyDate) elif (len(args) == 2) and r_changed_date and rqty: resource_list = dao.getResourcesByChangedDateQty(ChangedDate, Qty) elif (len(args) == 2) and r_changed_date and rprice: resource_list = dao.getResourcesByChangedDatePrice(ChangedDate, Price) elif (len(args) == 2) and r_changed_date and r_supply_date: resource_list = dao.getResourcesByChangedDateSupplyDate(ChangedDate, SupplyDate) elif (len(args) == 2) and rqty and rprice: resource_list = dao.getResourcesByQtyPrice(Qty, Price) elif (len(args) == 2) and rqty and r_supply_date: resource_list = dao.getResourcesByQtySupplyDate(Qty, SupplyDate) elif (len(args) == 2) and rprice and r_supply_date: resource_list = dao.getResourcesByPriceSupplyDate(Price, SupplyDate) elif (len(args) == 1) and rname: resource_list = dao.getResourcesByName(Name) elif (len(args) == 1) and r_changed_date: resource_list = dao.getResourcesByChangedDate(ChangedDate) elif (len(args) == 1) and rqty: resource_list = dao.getResourcesByQty(Qty) elif (len(args) == 1) and rprice: resource_list = dao.getResourcesByPrice(Price) elif (len(args) == 1) and r_supply_date: resource_list = dao.getResourcesBySupplyDate(SupplyDate) else: return jsonify(Error = "Malformed Query String"), 400 result_list = [] for row in resource_list: result = self.build_resource_dict(row) result_list.append(result) if not result_list: return jsonify(Error = "Resource Not Found"), 404 else: return jsonify(Resources = result_list) def getResourceById(self, rsid): dao = ResourceDAO() resource = dao.getResourceById(rsid) if not resource: return jsonify(Error = "Resource Not Found"), 404 else: result = self.build_resource_dict(resource) return jsonify(Resource = result) ***def insertResource(self, form): if len(form) != 1: return jsonify(Error = "Malformed Post Request"), 400 else: resource = form['resource'] if resource: dao = ResourceDAO() rsid = dao.insert(resource) result = self.build_resource_attributes(rsid, resource) return jsonify(Resource = result), 201 else: return jsonify(Error = "Unexpected attributes in post request"), 400
***def insertResource(self, form): if len(form) != 1: return jsonify(Error = "Malformed Post Request"), 400 else: resource = form['resource'] if resource: dao = ResourceDAO() rsid = dao.insert(resource) result = self.build_resource_attributes(rsid, resource) return jsonify(Resource = result), 201 else: return jsonify(Error = "Unexpected attributes in post request"), 400 ***def updateResource(self, rsid, form): dao = ResourceDAO() if not dao.getResourceById(rsid): return jsonify(Error = "Resource Not Found"), 404 else: resource = form['resource'] if resource: dao.update(rsid, resource) result = self.build_resource_attributes(rsid, resource) return jsonify(Resource = result), 200 else: return jsonify(Error = "Unexpected attributes in update request"), 400 ***def deleteResource(self, rsid): dao = ResourceDAO() if not dao.getResourceById(rsid): return jsonify(Error = "Resource Not Found"), 404
def searchRequestersOfThisResource(self, rsid, args): dao = RequesterDAO() daoRec = ResourceDAO() if not daoRec.getResourceById(rsid): return jsonify(Error="Resource Not Found"), 404 afirst = args.get('afirst') alast = args.get('alast') email = args.get('email') phone = args.get('phone') requesters_list = [] if (len(args) == 4) and afirst and alast and email and phone: requesters_list = dao.getRequestersOnThisResourceAfirstAlastEmailPhone( rsid, afirst, alast, email, phone) elif (len(args) == 3) and afirst and alast and email: requesters_list = dao.getRequestersOnThisResourceByAfirstAlastEmail( rsid, afirst, alast, email) elif (len(args) == 3) and afirst and alast and phone: requesters_list = dao.getRequestersOnThisResourceByAfirstAlastPhone( rsid, afirst, alast, phone) elif (len(args) == 3) and afirst and phone and email: requesters_list = dao.getRequestersOnThisResourceByAfirstPhoneEmail( rsid, afirst, phone, email) elif (len(args) == 3) and alast and email and phone: requesters_list = dao.getRequestersOnThisResourceByAlastEmailPhone( rsid, alast, email, phone) elif (len(args) == 2) and afirst and alast: requesters_list = dao.getRequestersOnThisResourceByAfirstAlast( rsid, afirst, alast) elif (len(args) == 2) and afirst and email: requesters_list = dao.getRequestersOnThisResourceByAfirstEmail( rsid, afirst, email) elif (len(args) == 2) and afirst and phone: requesters_list = dao.getRequestersOnThisResourceByAfirstPhone( rsid, afirst, phone) elif (len(args) == 2) and alast and email: requesters_list = dao.getRequestersOnThisResourceByAlastEmail( rsid, alast, email) elif (len(args) == 2) and alast and phone: requesters_list = dao.getRequestersOnThisResourceByAlastPhone( rsid, alast, phone) elif (len(args) == 2) and email and phone: requesters_list = dao.getRequestersOnThisResourceByEmailPhone( rsid, email, phone) elif (len(args) == 1) and afirst: requesters_list = dao.getRequestersOnThisResourceByAfirst( rsid, afirst) elif (len(args) == 1) and alast: requesters_list = dao.getRequestersOnThisResourceByAlast( rsid, alast) elif (len(args) == 1) and email: requesters_list = dao.getRequestersOnThisResourceByEmail( rsid, email) elif (len(args) == 1) and phone: requesters_list = dao.getRequestersOnThisResourceByPhone( rsid, phone) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in requesters_list: result = self.build_requester_dict(row) result_list.append(result) return jsonify(Requesters=result_list)