def getCategory(self): dao = ProductsDAO() category_list = dao.getCategory() results_list = [] for row in category_list: result = self.build_category_dict(row) results_list.append(result) return jsonify(Categories=results_list)
def getAllProduct(self): dao = ProductsDAO() products_list = dao.getAllProducts() results_list = [] for row in products_list: result = self.build_products_dict(row) results_list.append(result) return jsonify(Products=results_list)
def getAllPurchases(self, form): dao = ProductsDAO() purchase_list = dao.getAllPurchases() results_list = [] for row in purchase_list: result = self.build_purchases_dict(row) results_list.append(result) return jsonify(Purchases=results_list)
def getProductsByCategory(self, cid): dao = ProductsDAO() products_list = dao.getProductsByCategory(cid) results_list = [] for row in products_list: result = self.build_ProductsCategory_dict() results_list.append(result) return jsonify(Products=results_list)
def getAllProductsBySeller(self, uid): dao = ProductsDAO() products_list = dao.getAllProductsBySeller(uid) results_list = [] for row in products_list: result = self.build_ProductsSeller_dict(row) results_list.append(result) return jsonify(Products_By_User=results_list)
def insertCategory(self, form): if form and len(form) == 1: cat_name = form['cat_name'] if cat_name: dao = ProductsDAO() cid = dao.insertCategory(cat_name) result = {} result['cid'] = cid result['cat_name'] = cat_name return jsonify(Categories=result) else: return jsonify(Error="unexpected attributes in post request"), 400 else: return jsonify(Error="Malformed post request"), 400
def makePurchase(self, form): if form and len(form) == 3: uid = form['uid'] pid = form['pid'] p_qty = form['p_qty'] if uid and pid and p_qty: dao = ProductsDAO() caid = dao.makePurchase(uid, pid, p_qty) result = {} result['caid'] = caid result['uid'] = uid result['pid'] = pid result['p_qty'] = p_qty return jsonify(Cart_Item=result) else: return jsonify(Error="unexpected attributes in post request"), 400 else: return jsonify(Error="Malformed post request"), 400