def deletePart(self, pid): dao = PartsDAO() if not dao.getPartById(pid): return jsonify(Error="Part not found."), 404 else: dao.delete(pid) return jsonify(DeleteStatus="OK"), 200
def getPartById(self, pid): dao = PartsDAO() row = dao.getPartById(pid) if not row: return jsonify(Error="Part Not Found"), 404 else: part = self.build_part_dict(row) return jsonify(Part=part)
def getSuppliersByPartId(self, pid): dao = PartsDAO() if not dao.getPartById(pid): return jsonify(Error="Part Not Found"), 404 suppliers_list = dao.getSuppliersByPartId(pid) result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers=result_list)
def updatePart(self, pid, form): dao = PartsDAO() if not dao.getPartById(pid): return jsonify(Error="Part Not Found."), 404 else: if len(form) != 2: return jsonify(Error="Column Amount in Malform."), 400 else: res_type = form['res_type'] unit_price = form['unit_price'] if res_type and unit_price: dao.update(pid, res_type, unit_price) result = self.build_part_attributes( pid, res_type, unit_price) return jsonify(Part=result), 200 else: return jsonify( Error="Unexpected Attributes for Update Request."), 400
def updatePart(self, pid, form): dao = PartsDAO() if not dao.getPartById(pid): return jsonify(Error="Part not found."), 404 else: if len(form) != 4: return jsonify(Error="Malformed update request"), 400 else: pname = form['pname'] pprice = form['pprice'] pmaterial = form['pmaterial'] pcolor = form['pcolor'] if pcolor and pprice and pmaterial and pname: dao.update(pid, pname, pcolor, pmaterial, pprice) result = self.build_part_attributes( pid, pname, pcolor, pmaterial, pprice) return jsonify(Part=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400