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 insertParts(self, form): print("form: ", form) if len(form) != 4: return jsonify(Error="Malformed post request") Partsmaterial = form['PartsMaterial'] Partscolor = form['PartsColor'] Partsdescription = form['PartsDescription'] resourceid = form['ResourceID'] if Partsmaterial and Partscolor and Partsdescription and resourceid: dao = PartsDAO() Partsid = dao.insert( Partsmaterial, Partscolor, Partsdescription, resourceid, ) result = self.build_parts_attributes( Partsmaterial, Partscolor, Partsdescription, resourceid, ) return jsonify(Parts=result), 201 else: return jsonify(Error="Unexpected attributes in post request")
def deleteParts(self, Partsid): dao = PartsDAO() if not dao.getPartsById(Partsid): return jsonify(Error="Resource not found."), 404 else: dao.delete(Partsid) 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 getResourceIDByPartsID(self, Partsid): dao = PartsDAO() row = dao.getResourceIDByPartsID(Partsid) if not row: return jsonify(Error="Parts Not Found "), 404 else: Parts = self.build_parts_dict(row) return jsonify(Parts=Parts)
def getPartsByResourceID(self, resourceid): dao = PartsDAO() row = dao.getPartsByResourceID(resourceid) if not row: return jsonify(Error="Parts Not Found "), 404 else: Parts = self.build_partsdetails_dict(row) return jsonify(Parts=Parts)
def getAllParts(self): dao = PartsDAO() parts_list = dao.getAllParts() result_list = [] for row in parts_list: result = self.build_part_dict(row) result_list.append(result) return jsonify(Parts=result_list)
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 searchParts(self, args): supplierid = args.get("supplierid") dao = PartsDAO() Parts_list = [] if (len(args) == 1) and supplierid: Parts_list = dao.getPartsBySupplier(supplierid) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in Parts_list: result = self.build_parts_dict(row) result_list.append(result) return jsonify(Parts=result_list)
def insertPartJson(self, json): pname = json['pname'] pprice = json['pprice'] pmaterial = json['pmaterial'] pcolor = json['pcolor'] if pcolor and pprice and pmaterial and pname: dao = PartsDAO() pid = dao.insert(pname, pcolor, pmaterial, pprice) result = self.build_part_attributes(pid, pname, pcolor, pmaterial, pprice) return jsonify(Part=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def insertPartsJson(self, json): Partsmaterial = json['PartsMaterial'] Partscolor = json['PartsColor'] Partsdescription = json['PartsDescription'] resourceid = json['ResourceID'] if Partsmaterial and Partscolor and Partsdescription and resourceid: dao = PartsDAO() Partsid = dao.insert(Partsmaterial, Partscolor, Partsdescription, resourceid) result = self.build_parts_attributes(Partsid, Partsmaterial, Partscolor, Partsdescription, resourceid) return jsonify(Parts=result), 201 else: return jsonify(Error="Unexpected attributes in post request")
def insertPart(self, form): if len(form) != 4: return jsonify(Error="Malformed post request"), 400 else: pname = form['pname'] pprice = form['pprice'] pmaterial = form['pmaterial'] pcolor = form['pcolor'] if pcolor and pprice and pmaterial and pname: dao = PartsDAO() pid = dao.insert(pname, pcolor, pmaterial, pprice) result = self.build_part_attributes(pid, pname, pcolor, pmaterial, pprice) return jsonify(Part=result), 201 else: return jsonify( Error="Unexpected attributes in post 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) != 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 searchParts(self, args): color = args.get("color") material = args.get("material") dao = PartsDAO() parts_list = [] if (len(args) == 2) and color and material: parts_list = dao.getPartsByColorAndMaterial(color, material) elif (len(args) == 1) and color: parts_list = dao.getPartsByColor(color) elif (len(args) == 1) and material: parts_list = dao.getPartsByMaterial(material) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in parts_list: result = self.build_part_dict(row) result_list.append(result) return jsonify(Parts=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) != 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
def updateResourceJson(self, Partsid, json): dao = PartsDAO() if not dao.getPartsById(Partsid): return jsonify(Error="Parts not found."), 404 else: Partsmaterial = json['PartsMaterial'] Partscolor = json['PartsColor'] Partsdescription = json['PartsDescription'] if Partsmaterial and Partscolor and Partsdescription: dao.update(Partsid, Partsmaterial, Partscolor, Partsdescription) resourceid = dao.getResourceIDByPartsID(Partsid) result = self.build_parts_attributes(Partsid, Partsmaterial, Partscolor, Partsdescription, resourceid) return jsonify(Parts=result), 400 else: return jsonify( Error="Unexpected attributes in update request"), 400
def getCountByPartId(self): dao = PartsDAO() result = dao.getCountByPartId() #print(self.build_part_counts(result)) return jsonify(PartCounts=self.build_part_counts(result)), 200