def getResourceFullInfo(self, resource_id): resource_dao = ResourceDAO() category = resource_dao.getResourceById(resource_id)[2] if category == 1: return FuelHandler().getFuelByResourceId(resource_id) elif category == 2: return FoodHandler().getFoodByResourceId(resource_id) elif category == 3: return MedicineHandler().getMedicineByResourceId(resource_id) elif category == 4: return ToolHandler().getToolByResourceId(resource_id) elif category == 5: return ClothHandler().getClothByResourceId(resource_id) elif category == 6: return HeavyEquipHandler().getHeavyEquipByResourceId(resource_id) elif category == 7: return WaterHandler().getWaterByResourceId(resource_id) elif category == 8: return MedDeviceHandler().getMedDeviceByResourceId(resource_id) elif category == 9: return BatteryHandler().getBatteryByResourceId(resource_id) elif category == 10: return GeneratorHandler().getGeneratorByResourceId(resource_id) elif category == 11: return IceHandler().getIceByResourceId(resource_id) else: return jsonify(Error="Invalid category"), 400
def deleteResource(self, r_id): dao = ResourceDAO() if not dao.getResourceById(r_id): return jsonify(Error = "Resource not found."), 404 else: dao.delete(r_id) return jsonify(DeleteStatus = "OK"), 200
def getResourceById(self, r_id): dao = ResourceDAO() resources_list= dao.getResourceById(r_id) if not resources_list: return jsonify(Error="Resource Not Found"), 404 else: result = self.build_resource_dict(resources_list) return jsonify(Resource=result)
def getResourceById(self, resource_id): resource_dao = ResourceDAO() row = resource_dao.getResourceById(resource_id) if not row: return jsonify(Error="Resource not found"), 404 else: resource = self.build_resource_dict(row) return jsonify(Resource=resource)
def searchSupplierOfThisResourceOnThisRegion(self,rname, rsid, args): daoRes = ResourceDAO() daoRegion = RegionDAO() dao = SupplierDAO() if not daoRegion.getRegionByName(rname): return jsonify(Error = 'Region Not Found'), 404 if not daoRes.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') suppliers_list = [] if(len(args) == 4) and afirst and alast and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastEmailPhone(rname, rsid, afirst, alast, email, phone) elif(len(args) == 3) and afirst and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastEmail(rname, rsid, afirst, alast, email) elif(len(args) == 3) and afirst and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastPhone(rname, rsid, afirst, alast, phone) elif(len(args) == 3) and afirst and phone and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstPhoneEmail(rname, rsid, afirst, phone, email) elif(len(args) == 3) and alast and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastEmailPhone(rname, rsid, alast, email, phone) elif(len(args) == 2) and afirst and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlast(rname, rsid, afirst, alast) elif(len(args) == 2) and afirst and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstEmail(rname, rsid, afirst, email) elif(len(args) == 2) and afirst and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstPhone(rname, rsid, afirst, phone) elif(len(args) == 2) and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastEmail(rname, rsid, alast, email) elif(len(args) == 2) and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastPhone(rname, rsid, alast, phone) elif(len(args) == 2) and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByEmailPhone(rname, rsid, email, phone) elif(len(args) == 1) and afirst: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirst(rname, rsid, afirst) elif(len(args) == 1) and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlast(rname, rsid, alast) elif(len(args) == 1) and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByEmail(rname, rsid, email) elif(len(args) == 1) and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByPhone(rname, rsid, phone) else: return jsonify(Error = "Malformed query string"), 400 result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers = result_list)
def getRequestersOfThisResource(self, rsid): dao = RequesterDAO() daoRec = ResourceDAO() if not daoRec.getResourceById(rsid): return jsonify(Error="Resource Not Found"), 404 requesters_list = dao.getRequestersOnThisResource(rsid) result_list = [] for row in requesters_list: result = self.build_requester_dict(row) result_list.append(result) return jsonify(Requesters=result_list)
def getSuppliersOfThisResource(self, rsid): daoRes = ResourceDAO() dao = SupplierDAO() if not daoRes.getResourceById(rsid): return jsonify(Error = 'Resource Not Found'), 404 suppliers_list = dao.getSuppliersOfThisResource(rsid) result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Supplier = result_list)
def getResourceRegion(self, rsid): daoRes = ResourceDAO() dao = RegionDAO() if not daoRes.getResourceById(rsid): return jsonify(Error='Resource Not Found'), 404 regions_list = dao.getResourceRegion(rsid) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
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 getSupplierOfThisResourceOnThisCity(self, cname, rsid): daoRes = ResourceDAO() daoCity = CityDAO() dao = SupplierDAO() if not daoCity.getCityByName(cname): return jsonify(Error = 'City Not Found'), 404 if not daoRes.getResourceById(rsid): return jsonify(Error = 'Resource Not Found'), 404 suppliers_list = dao.getSupplierOfThisResourceOnThisCity(cname, rsid) result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Supplier = result_list)
***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 else:
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)