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 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 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