def updateSupplierJson(self, supplierid, json): dao = SuppliersDAO() if not dao.getSupplierById(supplierid): return jsonify(Error="Admin not found."), 404 else: username = json['UserName'] password = json['Password'] email = json['Email'] slocation = json['SLocation'] affiliation = json['affiliation'] firstname = json['FirstName'] lastname = json['LastName'] dateofbirth = json['DateofBirth'] gender = json['Gender'] categoryid = json['CategoryID'] categoryname = json['CategoryName'] if username and password and email and slocation and affiliation and firstname and lastname and dateofbirth and gender and categoryid and categoryname: dao.update(supplierid, username, password, email, slocation, affiliation, firstname, lastname, dateofbirth, gender, categoryid, categoryname) result = self.build_suppliers_attributes( supplierid, username, password, email, slocation, affiliation, firstname, lastname, dateofbirth, gender, categoryid, categoryname) return jsonify(Administrators=result), 200
def updateSupplier(self, supplierid, form): dao = SuppliersDAO() if not dao.getSupplierById(supplierid): return jsonify(Error="Supplier not found."), 404 else: if len(form) != 11: return jsonify(Error="Malformed update request"), 400 else: username = form['UserName'] password = form['Password'] email = form['Email'] slocation = form['SLocation'] affiliation = form['affiliation'] firstname = form['FirstName'] lastname = form['LastName'] dateofbirth = form['DateofBirth'] gender = form['Gender'] categoryid = form['CategoryID'] categoryname = form['CategoryName'] if username and password and email and slocation and affiliation and firstname and lastname and dateofbirth and gender and categoryid and categoryname: dao.update(username, password, email, slocation, affiliation, firstname, lastname, dateofbirth, gender, categoryid, categoryname) result = self.build_suppliers_attributes( username, password, email, slocation, affiliation, firstname, lastname, dateofbirth, gender, categoryid, categoryname) return jsonify(Suppliers=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def deleteSupplier(self, supplierid): dao = SuppliersDAO() if not dao.getSupplierById(supplierid): return jsonify(Error="Supplier not found."), 404 else: dao.delete(supplierid) return jsonify(DeleteStatus="OK"), 200
def getSupplierById(self, sid): dao = SuppliersDAO() row = dao.getSupplierById(sid) if not row: return jsonify(Error="Supplier Not Found"), 404 else: supplier = Supplier().build_dict_from_row(row) return jsonify(supplier)
def getSupplierById(self, suppID): dao = SuppliersDAO() row = dao.getSupplierById(suppID) if not row: return jsonify(Error="User not found"), 404 else: supplier = self.build_supplier_dict(row) return jsonify(Supplier=supplier)
def getSupplierById(self, SupplierID): dao = SuppliersDAO() row = dao.getSupplierById(SupplierID) if not row: return jsonify(Error="Supplier Not Found"), 404 else: suppliers = self.build_suppliers_dict(row) return jsonify(Suppliers=suppliers)
def getAddressBySid(self, sid): supplierDAO = SuppliersDAO() row = supplierDAO.getSupplierById(sid) if not row: return jsonify(Error="Supplier Not Found"), 404 # If supplier found, get all the stocks from that supplier else: dao = AddressesDAO() address = dao.getAddressBySid(sid) result_list = Address().build_dict_from_row(address) return jsonify(result_list)
def getSupplierTransactionById(self, sid, tid): supplierDAO = SuppliersDAO() supplier = supplierDAO.getSupplierById(sid) if not supplier: return jsonify(Error="Supplier Not Found"), 404 #If supplier found, get all the stocks from that supplier transactionsDao = ResourceTransactionsDAO() transaction = transactionsDao.getTransactionById(tid) if not transaction: return jsonify(Error="Transaction Not Found"), 404 result = ResourceTransaction().build_dict_from_table_no_sup_no_pur( transaction) return jsonify(result)
def getTransactionsBySupplierId(self, sid): supplierDAO = SuppliersDAO() row = supplierDAO.getSupplierById(sid) if not row: return jsonify(Error="Supplier Not Found"), 404 #If supplier found, get all the stocks from that supplier else: dao = ResourceTransactionsDAO() transactions_list = dao.getTransactionsBySid(sid) result_list = [] for row in transactions_list: transaction = ResourceTransaction().build_dict_from_row(row) result_list.append(transaction) return jsonify(result_list)
def getAvailabilityAnnouncementsBySID(self, sid): #TOMORROW FIX: WHATS UP WITH THE DIC. SOMETHING ABOUT ADMIN. supplierDAO = SuppliersDAO() supplier = supplierDAO.getSupplierById(sid) if not supplier: return jsonify(Error="Supplier Not Found"), 404 dao = AvailabilityAnnouncementsDAO() table = dao.getAnnouncementBySIDWithDetails(sid) if not table: return jsonify(Error="Availability Announcement Not Found"), 404 else: result = AvailabilityAnnouncement().build_dict_from_table_no_sup( table) return jsonify(result)
def getStocksBySupplierId(self, sid): # Check if supplier exists supplierDAO = SuppliersDAO() row = supplierDAO.getSupplierById(sid) if not row: return jsonify(Error="Supplier Not Found"), 404 #If supplier found, get all the stocks from that supplier else: dao = StocksDAO() stocks_list = dao.getStocksBySid(sid) result_list = [] for row in stocks_list: stock = Stock().build_dict_from_row_resource(row) result_list.append(stock) return jsonify(result_list)
def getAvailabilityAnnouncementByIds(self, sid, ann_id): supplierDAO = SuppliersDAO() supplier = supplierDAO.getSupplierById(sid) if not supplier: return jsonify(Error="Supplier Not Found"), 404 dao = AvailabilityAnnouncementsDAO() supplier = dao.getAnnouncementBySIDWithDetails(sid) if not supplier[0]: return jsonify(Error="Availability Announcement not found"), 404 result = dao.getAnnouncementByIdWithDetailsNoSup(ann_id) if not result: return jsonify(Error="Availability Announcement Not Found"), 404 else: newresult = AvailabilityAnnouncement( ).build_dict_from_table_no_sup(result) return jsonify(newresult)
def searchStocks(self, sid, args): dao = SuppliersDAO() row = dao.getSupplierById(sid) if not row: return jsonify(Error="Supplier Not Found"), 404 allowed_keys = {"rid", "rname", "catid", "catname"} allowed_range_keys = {"qtysum", "currentpriceperitem"} # Allow every query parameter stated in allowed_keys to have a min or max value max_and_min_keys = set() for key in allowed_range_keys: max_and_min_keys.add("max-" + key) max_and_min_keys.add("min-" + key) allowed_keys = allowed_keys.union(max_and_min_keys) allowed_keys = allowed_keys.union(allowed_range_keys) # Divide the args given by user into min, max and equal parameters for use in DAO max_args = {} min_args = {} equal_args = {} for key in args.keys(): if key in allowed_keys and key[0:4] == "max-": max_args[key[4:]] = args[key] elif key in allowed_keys and key[0:4] == "min-": min_args[key[4:]] = args[key] elif key not in allowed_keys: return jsonify(Error="Malfromed query string"), 400 else: equal_args[key] = args[key] # Added sid for searching specific uid equal_args['sid'] = sid # Get all the results for the search dao = StocksDAO() stocks_list = dao.getStocksByParamsNoSupplier(equal_args, max_args, min_args) result_list = [] for row in stocks_list: stock = Stock().build_dict_from_row_no_supplier(row) result_list.append(stock) return jsonify(result_list)