def updatePurchase(self, purid, form): dao = PurchaseDAO() if not dao.getPurchaseBypurId(purid): return jsonify(Error="Purchase not found."), 404 if len(form) != 10: return jsonify(Error="Malformed post request"), 400 else: purid = form['purid'] rid = form['rid'] reqid = form['reqid'] uid = form['uid'] purdate = form['purdate'] purprice = form['purprice'] purqty = form['purqty'] expdeliverydate = form['expdeliverydate'] carrier = form['carrier'] purstatus = form['purstatus'] if purid and rid and reqid and uid and purdate and purprice and purqty and expdeliverydate and carrier and purstatus: puridout = dao.update(purid, rid, reqid, uid, purdate, purprice, purqty, expdeliverydate, carrier, purstatus) result = self.build_pur_dict2(puridout, rid, reqid, uid, purdate, purprice, purqty, expdeliverydate, carrier, purstatus) return jsonify(Purchase=result), 201 else: return jsonify( Error="Unexpected attributes in put request"), 400
def insertPurchase(self, form): dao = PurchaseDAO() if len(form) != 9: return jsonify(Error="Malformed post request"), 400 else: rid = form['rid'] reqid = form['reqid'] uid = form['uid'] purdate = form['purdate'] purprice = form['purprice'] purqty = form['purqty'] expdeliverydate = form['expdeliverydate'] carrier = form['carrier'] purstatus = form['purstatus'] if rid and reqid and uid and purdate and purprice and purqty and expdeliverydate and carrier and purstatus: puridout = dao.insert(rid, reqid, uid, purdate, purprice, purqty, expdeliverydate, carrier, purstatus) result = self.build_pur_dict2(puridout, rid, reqid, uid, purdate, purprice, purqty, expdeliverydate, carrier, purstatus) return jsonify(Purchase=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def getPurchaseByStatus(self, purstatus): dao = PurchaseDAO() request_list = dao.getPurchaseByStatus(purstatus) result_list = [] for row in request_list: result = self.build_pur_dict(row) result_list.append(result) return jsonify(result_list)
def getPurchaseByCarrier(self, carrier): dao = PurchaseDAO() request_list = dao.getPurchaseByCarrier(carrier) result_list = [] for row in request_list: result = self.build_pur_dict(row) result_list.append(result) return jsonify(result_list)
def getPurchaseByReqID(self, reqid): dao = PurchaseDAO() row = dao.getPurchaseByReqID(reqid) if not row: return jsonify(Error="Request Not Found"), 404 else: result = self.build_pur_dict(row) return jsonify(result)
def getPurchaseByResourcesId(self, rid): dao = PurchaseDAO() request_list = dao.getPurchaseByResourcesId(rid) result_list = [] for row in request_list: result = self.build_pur_dict(row) result_list.append(result) return jsonify(result_list)
def getPurchaseBypurId(self, purid): dao = PurchaseDAO() row = dao.getPurchaseBypurId(purid) if not row: return jsonify(Error="Purchase Not Found"), 404 else: result = self.build_pur_dict(row) return jsonify(result)
def getAllPurchase(self): dao = PurchaseDAO() request_list = dao.getAllPurchase() result_list = [] for row in request_list: result = self.build_pur_dict(row) result_list.append(result) return jsonify(result_list)
def deletePurchase(self, purid): dao = PurchaseDAO() if not dao.getPurchaseBypurId(purid): return jsonify( Error="Cannot delete, purchase info not found."), 404 else: dao.delete(purid) return jsonify(DeleteStatus="OK"), 200
def getAllPurchases(self): dao = PurchaseDAO() purchase_list = dao.getAllPurchases() result_list = [] for row in purchase_list: result = self.build_purchase_dict(row) result_list.append(result) return jsonify(Purchase=result_list)
def getPurchaseById(self, pid): dao = PurchaseDAO() row = dao.getPurchaseById(pid) if not row: return jsonify(Error="Purchase Not Found"), 404 else: purchase = self.build_purchase_dict(row) return jsonify(Purchase=purchase)
def getPurchaseByQuantity(self, qty): dao = PurchaseDAO() purchase_list = dao.getPurchaseByQuantity(qty) if not purchase_list: return jsonify(Error="No Purchase Found"), 404 else: result_list = [] for row in purchase_list: result = self.build_purchase_dict(row) result_list.append(result) return jsonify(Purchase=result_list)
def insertPurchase(self, form): if len(form) != 6: return jsonify(Error="Malformed POST request"), 400 else: cid = form['cid'] sid = form['sid'] rid = form['rid'] qty = form['qty'] total = form['total'] ccnum = form['ccnum'] if cid and sid and rid and qty and total and ccnum: dao = PurchaseDAO() pid = dao.insert(cid, sid, rid, qty, total, ccnum) result = self.build_purchase_attributes( pid, cid, sid, rid, qty, total, ccnum) return jsonify(Purchase=result), 201 else: return jsonify( Error="Unexpected attributes in POST request"), 400
def searchPurchases(self, args): if len(args) > 6: return jsonify(Error="Malformed search string."), 400 else: pid = args.get("pid") cid = args.get("cid") sid = args.get("sid") rid = args.get("rid") qty = args.get("qty") total = args.get("total") dao = PurchaseDAO() purchases_list = [] if (len(args) == 2) and sid and total: purchases_list = dao.getPurchaseBySupplierAndTotal(sid, total) elif (len(args) == 2) and sid and qty: purchases_list = dao.getPurchaseBySupplierAndQuantity(sid, qty) elif (len(args) == 2) and cid and total: purchases_list = dao.getPurchaseByClientAndTotal(cid, total) elif (len(args) == 2) and cid and qty: purchases_list = dao.getPurchaseByClientAndQuantity(cid, qty) elif (len(args) == 1) and pid: purchases_list = dao.getPurchaseById(pid) elif (len(args) == 1) and cid: purchases_list = dao.getPurchaseByClientId(cid) elif (len(args) == 1) and sid: purchases_list = dao.getPurchaseBySupplierId(sid) elif (len(args) == 1) and rid: purchases_list = dao.getPurchaseByResourceId(rid) elif (len(args) == 1) and qty: purchases_list = dao.getPurchaseByQuantity(qty) elif (len(args) == 1) and total: purchases_list = dao.getPurchaseByTotal(total) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in purchases_list: result = self.build_purchase_dict(row) result_list.append(result) return jsonify(Purchases=result_list)