def insertRequest(self, form, nid): # New Resource if len(form) == 3: rname = form['rname'] catid = form['catid'] qty = form['qty'] if rname and catid and qty: dao = ResourcesDAO() resource = dao.getResourcesByRname(rname) if not resource: dao2 = CategoriesDAO() if not dao2.getCategoryById(catid): return jsonify(Error="Category Not Found"), 404 rid = dao.insert(rname, catid) else: rid = (resource[0])[0] dao = ResourceRequestsDAO() req_id = dao.insertRequest(nid) dao3 = ResourceRequestDetailsDAO() dao3.insertRequestDetails(req_id, rid, qty) table = dao.getRequestByIdWithDetails(req_id) if not table: return jsonify(Error="Request Not Found"), 404 else: print(table) result = ResourceRequest().build_dict_from_table_details( table) return jsonify(result) elif len(form) != 2: return jsonify(Error="Malformed post request"), 400 else: # Existing Resource rid = form['rid'] qty = form['qty'] if rid and qty: dao = ResourcesDAO() if not dao.getResourceById(rid): return jsonify(Error="Resource Not Found"), 404 dao2 = ResourceRequestsDAO() reqid = dao2.insertRequest(nid) dao3 = ResourceRequestDetailsDAO() dao3.insertRequestDetails(reqid, rid, qty) result = ResourceRequest().build_dict_from_row_resource( dao2.getRequestByIdWithDetails2(reqid)) return jsonify(result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def getLocationByResourceId(self, r_id): dao = ResourcesDAO() location = dao.getLocationByResourceId(r_id) if not location: return jsonify(Error = 'Resource Not Found'),404 result = location[0][0] return result
def deleteResource(self, resourceid): dao = ResourcesDAO() if not dao.getResourceById(resourceid): return jsonify(Error="Resource not found."), 404 else: dao.delete(resourceid) return jsonify(DeleteStatus="OK"), 200
def insertResourcesJson(self, json): rname = json['rname'] rtype = json['rtype'] rprice = json['rprice'] rlocation = json['rlocation'] rstock = json['rstock'] sid = json['sid'] if not SupplierDAO().getSupplierById(sid): return jsonify(Error="Supplier Not Found"), 404 if rlocation == 'Ponce': rlocation = '18.0107279,-66.6141375' elif rlocation == 'Mayaguez': rlocation = '18.201108,-67.1401665' elif rlocation == 'San Juan': rlocation = '18.46542,-66.1172515' if ',' in rlocation and len(rlocation) != 1: rlocation = "https://maps.google.com/?q=" + rlocation if rname and rtype and rprice and rlocation and rstock and sid: dao = ResourcesDAO() rid = dao.insert(rname, rtype, rprice, rlocation, rstock) dao.insertSupplierOfResource(sid, rid) result = self.build_resource_attributes(rid, rname, rtype, rprice, rlocation, rstock) return jsonify(Resoure=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def getAvailableByKeyword(self, keyword): dao = ResourcesDAO() row = dao.getAvailableByKeyword(keyword) if not row: return jsonify(Error="Resource Not Available"), 404 else: resource = self.build_resource_dict(row) return jsonify(ResourceSearchResult=resource)
def getAvailableResources(self): dao = ResourcesDAO() resource_list = dao.getAvailableResources() result_list = [] for row in resource_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(AvailableResources=result_list)
def getAResource(self, rid): dao = ResourcesDAO() row = dao.getAResource(rid) if not row: return jsonify(Error="Resource Not Found"), 404 else: request = self.build_resource_dict(row) return jsonify(Resource=request)
def getAllResourcesReserves(self): dao = ResourcesDAO() resource_list = dao.getAllResourcesReserves() result_list = [] for row in resource_list: result = self.build_resources_requests_dict(row) result_list.append(result) return jsonify(ResourcesReserves=result_list)
def getResourceById(self,r_id): dao = ResourcesDAO() row = dao.getResourceById(r_id) if not row: return jsonify(Eror = 'Resource Not Found'),404 else: r = self.build_resource_dict(row) return jsonify(Resource=r)
def getResourcesAvailableWeekly(self): dao = ResourcesDAO() resource_list = dao.getResourcesAvailableWeekly() result_list = [] for row in resource_list: result = self.build_resourcesAvailable_weekly_dict(row) result_list.append(result) return jsonify(ResourcesAvailableWeekly=result_list)
def getResourcesInNeedDaily(self): dao = ResourcesDAO() resource_list = dao.getResourcesInNeedDaily() result_list = [] for row in resource_list: result = self.build_resourcesInNeed_daily_dict(row) result_list.append(result) return jsonify(ResourcesInNeedDaily=result_list)
def getResourcesAvailableBySenateRegion(self): dao = ResourcesDAO() resource_list = dao.getResourcesAvailableBySenateRegion() result_list = [] for row in resource_list: result = self.build_resourcesAvailable_by_senate_region_dict(row) result_list.append(result) return jsonify(ResourcesAvailableBySenateRegion=result_list)
def sortResourcesAvailableByResourceName(self): dao = ResourcesDAO() resource_list = dao.sortResourcesAvailableByResourceName() result_list = [] for row in resource_list: result = self.build_resources_available_dict(row) result_list.append(result) return jsonify(SortResourcesAvailableByResourceName=result_list)
def getSenateAvailableStats(self): dao = ResourcesDAO() weekly_list = dao.getSenateStats() result_list = [] for row in range(0, 8): result = self.build_senate_available_dict(weekly_list, row * 16) result_list.append(result) return jsonify(SenateAvailabilityDashboard=result_list)
def getResourceByCategoryName(self, categoryname): dao = ResourcesDAO() row = dao.getResourcesByCategoryName(categoryname) if not row: return jsonify(Error="Resource Not Found "), 404 else: resource = self.build_resource_dict(row) return jsonify(Resource=resource)
def getResourceById(self, resourceID): dao = ResourcesDAO() resources_list = dao.getResourceById(resourceID) result_list = [] for row in resources_list: result = self.build_resourceInfoByID_dict(row) result_list.append(result) return jsonify(Resource=result_list)
def getResourceAvailabilityById(self, resourceid): dao = ResourcesDAO() row = dao.getResourceAvailabilityById(resourceid) if not row: return jsonify(Error="Resource Not Found "), 404 else: resource = self.build_resource_dict(row) return jsonify(Resource=resource)
def getAllResourcesInfo(self): dao = ResourcesDAO() resources_list = dao.getAllResourcesInfo() result_list = [] for row in resources_list: result = self.build_resourcesInf_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def getResourceBySupplier(self, collectionCenterID): dao = ResourcesDAO() resources_list = dao.getResourceByCollectionCenterID(collectionCenterID) result_list = [] for row in resources_list: result = self.build_resourcesBySupplier_dict(row) result_list.append(result) return jsonify(Resource=result_list)
def add(self, json): if json['type'] and json['name'] and json['description']: resource = ResourcesDAO().add(json) resource_list = to_specified_format(resource, RESOURCE_FORMAT) return jsonify(Reservation=resource_list), CREATED else: return jsonify( Error='Unexpected attributes in post request'), BAD_REQUEST
def getAllResources(self): dao = ResourcesDAO() resources_list = dao.getAllResources() result_list = [] for row in resources_list: result = Resource().build_dict_from_row(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: resource = Resource().build_dict_from_row(row) return jsonify(resource)
def getResourceById(self, resID): dao = ResourcesDAO() row = dao.getResourceById(resID) if not row: return jsonify(Error="User not found"), 404 else: resource = self.build_resource_dict(row) return jsonify(Resource=resource)
def getResourceRequestedByRequestID(self, rid, ord_id): dao = ResourcesDAO() requests = dao.getResourceRequestedByRequestID(rid, ord_id) dic = Dictionary() result_list = [] for row in requests: result = dic.build_resource_dict(row) result_list.append(result) return jsonify(Requests=result_list), 200
def getResourceAvailableByName(self, rname): dao = ResourcesDAO() requests = dao.getResourceAvailableByName(rname) dic = Dictionary() result_list = [] for row in requests: result = dic.build_resource_dict(row) result_list.append(result) return jsonify(Requests=result_list), 200
def getAllResourcesAvailableOrderByResourceName(self): dao = ResourcesDAO() resources_list = dao.getResourcesAvailableOrderByResourceName() result_list = [] for row in resources_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def deleteResource(selfself, resID): dao = ResourcesDAO() type = dao.getResourceType(resID) if not type: return jsonify(Error = "Resource not found."), 404 else: dao.delete(resID, type) #return jsonify(DeleteStatus = "OK"), 200 return "<h3>Resource with ID: " + resID + " was removed from the database.</h3>"
def getAllDailyStats(self): dao = ResourcesDAO() daily_list = dao.getDailyStats() result = [] result1 = self.build_daily_needs_dict(daily_list) result2 = self.build_daily_available_dict(daily_list) result.append(result1) result.append(result2) return jsonify(DailyDashboard=result)
def getAllResources(self): dao = ResourcesDAO() resources_list = dao.getAllResources() result_list = [] # resources_list = [0,0,'papel de toilet', 5, 10] for row in resources_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def getResourcesByCity(self, city): dao = ResourcesDAO() suppliers_list = dao.getResourcesByCity(city) if len(suppliers_list) == 0: return jsonify(Error="City Not Found"), 404 result_list = [] for row in suppliers_list: result = self.build_user_dict(row) result_list.append(result) return jsonify(Suppliers=result_list)