def deleteResources(self, rid): dao = ResourcesDAO() if not dao.getResourcesById(rid): return jsonify(Error="Resource not found."), 404 else: dao.delete(rid) return jsonify(DeleteStatus="OK"), 200
def getResourcesById(self, rid): dao = ResourcesDAO() row = dao.getResourcesById(rid) if not row: return jsonify(Error="Resource Not Found"), 404 else: resources = self.build_resource_dict(row) return jsonify(Resources=resources)
def getConsumerByResourcesId(self, rid): dao = ResourcesDAO() if not dao.getResourcesById(rid): return jsonify(Error="Resource Not Found"), 404 consumer_list = dao.getConsumerByResourcesId(rid) result_list = [] for row in consumer_list: result = self.build_consumer_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def updateResources(self, rid, form): dao = ResourcesDAO() if not dao.getResourcesById(rid): return jsonify(Error="Resource not found."), 404 else: if len(form) != 5: return jsonify(Error="Malformed update request"), 400 else: rname = form['rname'] rtype = form['rtype'] rprice = form['rprice'] rlocation = form['rlocation'] rstock = form['rstock'] if rname and rtype and rprice and rlocation and rstock: dao.update(rid, rname, rtype, rprice, rlocation, rstock) result = self.build_resource_attributes( rid, rname, rtype, rprice, rlocation, rstock) return jsonify(Resource=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400